Reputation: 6247
I have a UIScrollView with an image inside it. This is the code:
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
UIScrollView *imScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 96)];
[imScrollView addSubview:imView];
[imScrollView setContentSize:CGSizeMake(530, 96)];
[[self view] addSubview:imScrollView];
[imView release];
[imScrollView release];
}
This is what it looks like in portrait mode:
I want to know
1. How can I position the image exactly in the middle of the screen (horizontally).
2. How can I make sure this is going to be the same if the orientation switches to landscape. This is what currently the landscape looks like :
Thanks.
Upvotes: 0
Views: 499
Reputation: 17014
Try setting the autoresizingMask
property of your imView
just after you create it:
imView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
The UIView
class reference contains more info.
Upvotes: 1