Reputation: 41
I have a topbarlogo(header) that I load from an .xib -file. I use the following code to make the view fit on screen, because applying constraints in the xib does not work to make it fit the screen right (even though I would like it if I could just make constraints on the view as usual, but in the xib):
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"RaymioHeaderView" owner:nil options:nil];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIView *topView = [nibContents lastObject];
topView.frame = CGRectMake(0, 0, screenBounds.size.width, 78);
[self.view addSubview:topView];
}
Now when I rotate the screen to landscape it stays at the same width instead of filling out. I was kind of thinking that viewDidLoad would be called again when redrawing after rotation. Any help appreciated.
Upvotes: 1
Views: 1798
Reputation: 735
Yeah, viewDidLoad will not be called again when the interface rotates. If constraints are out of the question, I usually like to use an autoresizingMask instead.
topView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Upvotes: 3