Reputation: 5635
I am making iOS view using storyboard and autolayout. I placed image in centre of screen. On all devices (iPhone 4, iPhone 5, iPhone 6 and iPhone 6 Plus) size is the same. It looks too big on iPhone 4 and too small on 6 Plus. How to make image's size relative to screen size. I'd like to use constraints and auto layout here, but all answers appreciated.
Upvotes: 0
Views: 2168
Reputation: 27438
There are two options.
1) Give constraints like top, bottom, leading and trailing.
and
2) Give constraints like leading, trailing, top (or bottom which is apropriate) and aspect ratio. (This will keep your imageview's shape same in all size)
Hope this will help :)
Upvotes: 3
Reputation: 8914
You need to surround image view with constraints (Top, Trailing, Bottom, Leading) and don't give height and width constraints to image view as it fix the image view.
The image view will set according to screen size doesn't matter what device it is (iPhone 4, iPhone 5, iPhone 6, iPhone 6 Plus, iPod, iPad, iPad Pro, etc.)
Upvotes: 0
Reputation: 1935
Use these constraints for your UIImageView:
It will create 50 trailing space to left, right, top and bottom and will resize according to the screen size. The point is, don't set fixed width and height. Instead set Leading, Trailing, Bottom and Top constraints.
Upvotes: 1