0

I would like to set an image view in respect with screen and not the view. I have tried doing something like the following, but it does not work.

bgImgView = UIImageView(image: bgImage)
var scrFrame = UIScreen.mainScreen().bounds.size
bgImgView.frame = CGRectMake(0, -self.view.frame.origin.y, scrFrame.width, scrFrame.height)
self.view.addSubview(self.bgImgView)
Tom Elliott
  • 1,908
  • 1
  • 19
  • 39
Marcia
  • 3
  • 2

1 Answers1

0

You could add the view to the main app window on top of all other views, although this could cause you issues relating to device orientation.

bgImgView = UIImageView(image: bgImage)
bgImgView.backgroundColor = UIColor.redColor()
var scrFrame = UIScreen.mainScreen().bounds.size
bgImgView.frame = CGRectMake(0, 0, scrFrame.width, scrFrame.height)
var appDelegate : AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate;
appDelegate.window?.addSubview(self.bgImgView)

Depending on what you're intending to do with the image view, you could also create a modal view for this purpose (which I'd recommend over the above).

Tom Elliott
  • 1,908
  • 1
  • 19
  • 39