jcromanu
jcromanu

Reputation: 1481

Resize image background iOS

Hi I have developed an app for ios 7 and the 3.5 display , actually i am applying all the auto layout constraints needed for the 4 inch display but for me it´s not clear if once i apply auto layout the background image will resize to fit the 4 inch display or if i need to have a new background image to fit in the 4 inch display.

Upvotes: 1

Views: 1075

Answers (3)

Hanny
Hanny

Reputation: 1342

You should use the image compatible with the 4-inch display and set the ImageView contentMode property to UIViewContentModeScaleAspectFit in the storyboard or in your code. So no matter what the screen size is, it will automatically be adjusted and the image will not even get pixelated.

Upvotes: 0

Bohdan Orlov
Bohdan Orlov

Reputation: 304

That depends on .contentMode property. The default value of this property is UIViewContentModeScaleToFill. In this mode your image will be stretched to fill UIImageView's bounds. But you might be interested in UIViewContentModeScaleAspectFit or UIViewContentModeScaleAspectFill in order to preserve aspect ratio.

Upvotes: 0

user2105505
user2105505

Reputation: 708

From memory, I believe it would stretch/shrink the image if you used the same image and allowed to automatically resize. I think that the best course would be to have two images and set the proper image programmatically, deepening on UIDevice's idiom property.

If you don't care if the top and bottom edges get cut off on the smaller screen, you could simply make the UIImageView the size of a 4-inch screen, delete any constraints, and center the view. Good luck!

Upvotes: 1

Related Questions