I’m using xcode 4.5 (incase that makes any difference) along with a Storyboard and I’m trying to do something seemingly very simple without any luck. In my storyboard view I have placed a UIView component as you can see in the image here http://www.shopow.co.uk/assets/storyboard-view.png where the green section is the UIView which has a height of 100
In the viewDidLoad method I’ve added the following code
NSLog(@"View Height: %f", self.testView.bounds.size.height);
CGRect viewFrame = self.testView.frame;
CGSize newSize = CGSizeMake(viewFrame.size.width, 300);
viewFrame.size = newSize;
self.testView.frame = viewFrame;
NSLog(@"View Height: %f", self.testView.bounds.size.height);
From what I’ve read about resizing stuff I’d assume the green section to resize to be 300 high however this doesn’t happen although the output in the log window shows the following
2012-10-19 13:05:28.015 TableTest[54318:c07] View Height: 460.000000
2012-10-19 13:05:28.016 TableTest[54318:c07] View Height: 300.000000
Notice the initial height being 460 rather than 100 which may mean something!
iOS simulator shows this http://www.shopow.co.uk/assets/simulator-view.png
I must be overlooking something obvious as far as I can tell this is not working as expected. Any guidance would be greatly appreciated.
I’m not sure if it will fix your problem, but you should really do your view resizing in
viewWillAppearrather thanviewDidLoad.viewDidLoadliterally means what it says, ‘the view has loaded’. However, at this point your nib may not have set up the view as you would expect.As a test, try logging the following in both
viewDidLoadandviewWillAppearYou should see that in both methods you get different results. The
viewWillAppearmethod is more likely to be correct as the view has been set up and is ready to be presented.I personally don’t use Interface Builder all that much as it causes more headaches than I can deal with but perhaps your auto-resizing masks or elastic constraints are set which is affecting the dimensions of your view?