awp2004
awp2004

Reputation: 41

My UIView not resizing width on rotation

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

Answers (1)

Adam Kaump
Adam Kaump

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

Related Questions