user2062943
user2062943

Reputation: 9

Put resizable background image in IOS

I had a background image on my app developed for the iphone 4 screen size, however now with the larger iphone 5 screen size the image is too small and I ideally want it to resize automatically for the iphone 5 screen size. The image is displayed via an imageView object which I hoped would mean it would automatically resize for the new screen size. Is there a way to do this please? Thank you

Upvotes: 0

Views: 52

Answers (2)

scollaco
scollaco

Reputation: 922

Use this:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yourImage"]];

And then you don't need to use UIImageView to create a background. If you wanna use UIImageView anyway, you can use Autolayout:

  1. Go to Storyboard and select the UIImageView
  2. Click on "Pin" button and add the 4 Constrains (left, top, right and bottom).

Upvotes: 1

Andy Obusek
Andy Obusek

Reputation: 12852

Two steps:

  • Use Autolayout constraints to ensure that the UIImageView itself fills the screen.
  • Set the resize mask on the UIImage for the UIImageView to stretch the image as you'd like to fill the UIImageView.

Upvotes: 1

Related Questions