What I've heard there are no real way) to set a background image for a view in swift (tex self.view.background image. After googling around I found this:
var imageView = UIImageView(frame: self.view.frame) // set as you want
var image = UIImage(named: "fade bg3")!
imageView.image = image
self.view.addSubview(imageView)
self.view.sendSubviewToBack(imageView)
It worked but the statusbar (with the clock, battery status and network ex) has that background too. Can I prevent this?
This was the solution
UIImageView(frame: CGRectMake(self.view.frame.origin.x, 20, self.view.frame.size.width, self.view.frame.size.height))
只需隐藏这些屏幕的状态栏即可。
You really should implement prefersStatusBarHidden
on your view controller(s):
override func prefersStatusBarHidden() -> Bool {
return true
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.