Reputation: 1084
In my IOS app I want to display the biggest variation of an image that can be fully displayed on the device. I want to do it without resizing the image to be larger or smaller so that the image doesn't seem blurry.
On my webserver I have 3 variations of the same image. To keep it simple let's say they only differ in width: 640, 750 and 1000.
An iPhone 5 will display the 640 width image. An iPhone 6 will display the 750 width image. An iPhone 6+ will display the 1000 width image.
I can easily get the size of a UIImageView in order to download the right image, but how to do I set an Auto Layout Constraint on the UIImageView that sets the UIImageView to the right width?
If I set a low priority <= 1000 width constraint on the UIImageView, then the image is displayed at a width of 1000 regardless of the size of the device. This is true even when I set the UIImageView to have a low Content Compression Resistance Priority.
I am using XCode, Objective C and IOS 8.
If I'm going about this wrong please tell me.
Thank you!
Upvotes: 0
Views: 81
Reputation: 2721
easy solution would be to make a width constraint of the UIImageView, then create an outlet for the same.
Now inside the code , set constraint.constant value by calculating according to the device.
Upvotes: 2