Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

iPhone 5 simulator - screen size issue??

I have iPhone 4 (real one) to test my application. So far everything is fine. But I tried it with iPhone 5/5S simulator (iOS7.1), my app has some vertical margins and this code:

CGRect screenRect = [[UIScreen mainScreen] bounds];
NSLog(@"%f , %f", screenRect.size.width, screenRect.size.height);

still shows 320x480 resolution. Does it mean, that with real iPhone 5/5S I will get the same gap between the top and bottom edges and my app??

How can I set dynamically my UIViewControllers' width and height to fit the screen? (I am using storyboard just to set the UIView classes to them)

1 Answer

Are you setting the frame explicitly to specific points? If you want your view controller's view to take of the full screen you either need to use autoresize masks or AutoLayout.

Using resize masks:

self.view.frame = 
CGRectMake(0,  0,  CGRectGetWidth(parentView.bounds),  CGRectGetHeight(parentView.bounds);
self.view.autoresizeMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[parentView addSubview:self.view];

This will make the view controller's view always resize to match the parents size. If you're using a Storyboard then the masks can be set in the inspector.

.

The same can be done with AutoLayout.