BadmintonCat BadmintonCat - 1 year ago 136
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