I have an image displaying in a CGRect. how do I center the rect in the view?
here’s my code:
UIImage * image = [UIImage imageNamed:place.image];
CGRect rect = CGRectMake(10.0f, 90.0f, image.size.width, image.size.height);
UIImageView * imageView = [[UIImageView alloc] initWithFrame:rect];
[imageView setImage:image];
I’ve tried imageView.center but to no effect.
thanks in advance.
UIView’s
centeris a property, not a method.You need to calculate the actual location you want to put it in. You can do this by setting the frame of the view, or by setting its center, which is simpler in your case.
You don’t say what view you then go make
imageViewa subview of. If you’re putting it inside something calledsuperview, you could do this: