Venky Siddani
Venky Siddani

Reputation: 29

How to set two different sizes of background images for activity as landscape and portrait modes in iOS using swift

I want to set two different sizes of background images: one for landscape mode, another one is portrait mode. I wrote the programme like this, but I knew it was showing only portrait mode. What is the condition I should write here for landscape mode? I am very new to swift language.

@IBOutlet var img: UIImageView!

func loadimage()
{
    let image = UIImage (named: "Vertical");
    self.img.image  = image
}

Upvotes: 1

Views: 659

Answers (1)

Parth Adroja
Parth Adroja

Reputation: 13514

You can check the device orientation like this and then set the image.

override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
        let app = UIApplication.sharedApplication()

        if (app.statusBarOrientation.isLandscape) {
            // Image Code

        }
        else {
            // Image Code
        }

Upvotes: 3

Related Questions