class CustomView: UIView {
var subViewColor:UIColor
var subViewMessage:String
override init(frame:CGRect) {
super.init(frame:frame)
}
init(subViewColor:UIColor,subViewMessage:String){
self.subViewColor = subViewColor
self.subViewMessage = subViewMessage
super.init()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Tôi có một lớp học nơi tôi muốn người dùng để khởi tạo một giao diện tùy chỉnh bằng cách đưa ra các thuộc tính như:Override của UIView trong nhanh chóng
let myView = CustomLoadingView(initialize properties here)
Nếu người dùng không muốn khởi tạo riêng của họ tài sản, tôi muốn khởi CustomLoadingView
sử dụng thuộc tính mặc định ...
let myView = CustomLoadingView() // this should initialize using default value
Tuy nhiên, với điều này, tôi nhận được lỗi này:
Must call a designated intializer of the superclass UIView
Điều này chỉ hoạt động đối với tôi nếu tôi gọi 'self.init (frame: frame)' là điều đầu tiên trong 'tiện ích init' phương pháp – Joseph