Reputation: 421
How do I stretch the background image in swift programatically. This is my current code
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "back.png")!)
I know how to strech if it was just UIImageView, but not sure about self.view
Upvotes: 1
Views: 2374
Reputation: 5602
Xcode 8.0 | SWift 3.0
let img: UIImage = UIImage(named: "YOURIMAGENAME")!
self.view.layer.contents = img.cgImage
Hope it will help everyone.
Upvotes: 3
Reputation: 1233
You can try it with UIEdgeInsets
var backImage = UIImage(named: "1234")
var resizablebackImage = backImage?.resizableImageWithCapInsets(UIEdgeInsets(top:10,left:0,bottom:10,right:0))
self.view.backgroundColor = UIColor(patternImage:resizablebackImage!)
Upvotes: 1