BadmintonCat BadmintonCat - 2 years ago 156
Swift Question

UIView Background Image not showing

I've defined a bg image in the Xcode Images.xcassets and want to use it as background for a view but the bg stays black. I'm using:

override func viewDidLoad()
view.backgroundColor = UIColor(patternImage: UIImage(named: "background_ipad"));

this should work according to some other tickets on SO but for some reason the background stays black, not showing the image. Any ideas why this would happen?

Answer Source

Use this code

view.layer.contents = UIImage(named:"Image_Name").CGImage
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download