Reputation: 29
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
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