user3781174
user3781174

Reputation: 235

Auto layout a UIImage for all devices

I'm developing an application for various versions of the iphone in my case I created a file .xib type and a view with a size of 320x480, within this view there is a UIImage that occupies the entire view (320x480).

When I test my app on iphone 4 or 4s screen is perfect, but when I test on the iphone 5, 5s, 6, 6 plus, is a huge blank space and the image is not in full screen like the iphone 4 versions .

To try and fix this, I put autolayout, in my view and in the UIImage, besides constraints add to my UIImage with trailling, leading, top, bottom space to my superview but that did not work.

How could solve this problem and make my UIImage extend or decrease for each of the versions of the iphone?

EDIT

This is the image running in iphone 4, 4s:

enter image description here

And this is the image running in iphone 5, 5s:

enter image description here

Why the black space in top and bottom? how can I solve this? and put the image full screen for all devices?

Upvotes: 0

Views: 1802

Answers (1)

Aggressor
Aggressor

Reputation: 13551

You need to set constraints.

I suggest you upgrade to Xcode 6 and look at the new size class system.

With the size classes you only have to handle 4 situations: Its all explained here: http://carpeaqua.com/2014/06/14/thinking-in-terms-of-ios-8-size-classes/

Regarding constraints look at this (AutoLayout/ Adaptive UI): http://www.youtube.com/watch?v=p5wD8dvSDbM

If you don't use the auto layout, you will have some bulk in your code as you will need to manually set the dimensions of the UIView like this (and if orientation changes you will need to readjust this)

_background = [[UIView alloc] initWithFrame:CGRectMake(0,0,[UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];

Upvotes: 0

Related Questions