user6125284
user6125284

Reputation:

Different images for different dimensions on iOS

I am making an application which I would like to use the same image for multiple dimensions without stretching or cropping the image.

Can I make different images each supporting a dimension?

Upvotes: 1

Views: 119

Answers (2)

Jatin Chauhan
Jatin Chauhan

Reputation: 1127

You can use contentMode as UIViewContentModeScaleAspectFit of UIImageView's Property.

It will be fit to your imageView, and will not be stretching or cropping. It will mainain aspect ratio of image. i.e

imgDevider.contentMode = UIViewContentModeScaleAspectFit;

Upvotes: 1

Koby Douek
Koby Douek

Reputation: 16675

If you want to prevent stretching, you would have to create a different image for all supported iOS dimensions. Then, using your code, choose the correct image source according to the device's dimension.

Read here about getting the device dimensions.

Read here about changing the image source.

Upvotes: 0

Related Questions