Search code examples
iosuser-interfaceautolayout

Image size relative to screen size


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.


Solution

  • 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 :)