Search code examples
ioscocoa-touchscreen-size

How to set the background image according to screen size?


I want to set an image according to screen size. I've been going through many codes on it but I've not found a working solution yet. I'm using Xcode 5.1.1 and Iphone Retina 4inch. Whenever I add my background image, it becomes huge and goes out of screen size. Kindly help me.


Solution

  • Use the code from Anbu's answer to get the screen height and set the image to aspectFit to avoid it from getting huge and out of bounds:

    yourImageview.contentMode = UIViewContentModeScaleAspectFit;
    yourImageview.clipsToBounds = YES;