import UIKit
class CustomPrettyView: UIView {
override class func awakeFromNib() {
layer.cornerRadius = 20
}
}
Why it does not work?
import UIKit
class CustomPrettyView: UIView {
override class func awakeFromNib() {
layer.cornerRadius = 20
}
}
Why it does not work?
class func declare type level methods. They are similar to static func but class func methods can be overridden by subclasses.
There are two implementations of func awakeFromNib that you can override:
Only instance level method has access to non-static members of a class like layer, mask, supreview and so on. Read here more about type level methods: https://docs.swift.org/swift-book/LanguageGuide/Methods.html
Thus, by removing class keyword you'll fix the issue:
override func awakeFromNib() {
super.awakeFromNib()
// rest of code
}