I'm able to set a patterned background using the following code
view.backgroundColor = UIColor(patternImage: UIImage(named: "imagefilename")!)
You see a black background, because there is no view behind the view you are modifying.
If you can't change your image (to make it non-transparent), you could add a subview to your view containing this image:
//create a new UIView let otherView = UIView(frame: view.frame) otherView.backgroundColor = UIColor(patternImage: UIImage(named: "imagefilename")!) //now add your new view as subview to the existing one view.addSubview(otherView)
The transparent parts should now be white by default. You can change this by modifying
Note: If you add other UI-elements, they might be hidden under
otherView because they are added as subviews of
view. To prevent this, you can add them as subview of
otherView or reorder the layers. (
I wrote all the code on the fly, so there might be some syntax errors. But the general idea behind this code should work.