我得到Property self.color not initialized as super.init call
错误,下面的代码。我该如何正确覆盖init(frame :)函数?我想通过color
以及init调用。如何使用UIView框架创建自定义init
class CircleView: UIView {
// properties
let color: UIColor
init(frame: CGRect, color: UIColor) {
self.color = color
super.init(frame: frame)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func drawRect(rect: CGRect) {
...
}
}
退房http://stackoverflow.com/questions/24021093/error-in-swift-class-property-not-initialized-at-super-init-call 此外,可能需要尝试var而不是let。也可以设置颜色的默认值。 – shim 2014-12-04 18:09:36
将'let color:UIColor'更改为'var color:UIColor!' – bbarnhart 2014-12-04 18:12:11
这两个提示都可以使用。我正在服用@bbarnhart。谢谢。很高兴接受为答案.. – 2014-12-04 18:14:18