This error occurs because the image "bg.png" does not exist. Typically, when you import images into the Assets.xcassets folder, the file extension is deleted. So try the following:
self.view.backgroundColor = UIColor(patternImage: UIImage(named:"bg")!)
You will notice that the background will not look as expected, you need to do the following as described here :
UIGraphicsBeginImageContext(self.view.frame.size) UIImage(named: "bg")?.draw(in: self.view.bounds) let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()! UIGraphicsEndImageContext() self.view.backgroundColor = UIColor(patternImage: image)
drdrdrdr
source share