我正在为我的项目使用 Swift
。创建了一个自定义 UIView
类,如下所示:
class AppBgView: UIView {
override init (frame : CGRect) {
super.init(frame : frame)
//self.isMemberOfClass(<#aClass: AnyClass#>)
}
convenience init () {
self.init(frame:CGRect.zeroRect)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.backgroundColor = UIColor(patternImage: UIImage(named: "BGround.png")!)
}
}
尝试在所需的 init()
方法中设置背景图像。但背景图像似乎没有改变。任何建议将不胜感激。谢谢。
最佳答案
在每个方法中放置一个断点,看看调用了哪个构造函数。 您将需要移动线路
self.backgroundColor = UIColor(patternImage: UIImage(named: "BGround.png")!)
到被调用的构造函数。
在 Swift 中,一个类必须至少有一个指定的初始化器。 您可能需要从 init() 中删除单词convenience。
试一试: UIColor(patternImage:UIImage(named: "BGround.png")!).CGColor
关于ios - 自定义 UIView 背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33613923/