當我嘗試在自定義視圖文件中設置漸變時,XCode 8中出現錯誤「方法不覆蓋任何方法從它的超類」。 該代碼是方法不會覆蓋任何方法從它的超類Xcode 8
override class func layerClass() -> AnyClass {
return CAGradientLayer.self
}
當我刪除替換,這種錯誤發生 「方法‘layerClass()’與從超類的UIView'與目標C選擇‘layerClass’與吸氣劑的衝突關於‘layerClass’同樣的Objective-C中選擇」
完整的代碼是在這裏:
import UIKit
@IBDesignable
class CustomView: UIView {
override class func layerClass() -> AnyClass {
return CAGradientLayer.self
}
var gradientLayer: CAGradientLayer {
return layer as! CAGradientLayer
}
override func draw(_ rect: CGRect) {
// Drawing code
layer.masksToBounds = true
layer.borderWidth = 10.0
layer.borderColor = UIColor(red: 0.0, green: 64/225.0, blue: 128/225.0, alpha: 1.0).cgColor
layer.cornerRadius = 20.0
let startColor = UIColor(red: 102/225.0, green: 204/225.0, blue: 1.0, alpha: 1.0).cgColor
let endColor = UIColor(red: 0.0, green: 128/225.0, blue: 1.0, alpha: 1.0).cgColor
gradientLayer.colors = [startColor,endColor]
}
}
我是新來的iOS plz幫助我
'覆蓋類VAR layerClass:AnyClass {返回CAGradientLayer.self}' –