如何以编程方式快速拉伸背景图像。这是我目前的代码
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "back.png")!)
如果它只是UIImageView,我知道如何拉伸,但不确定self.view
答案 0 :(得分:2)
Xcode 8.0 | SWift 3.0
let img: UIImage = UIImage(named: "YOURIMAGENAME")!
self.view.layer.contents = img.cgImage
希望它能帮到每个人。
答案 1 :(得分:1)
您可以使用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!)