I had the same issue in a UITableViewCell. This workaround should work
override func drawRect(rect: CGRect) {
super.drawRect(rect)
customInit()
}
var initialized = false
func customInit(){
if !initialized{
initialized = true
}
}
In your case, it should look like this:
class SliderView: UIView {
let trackLayer = CAShapeLayer()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func drawRect(rect: CGRect) {
super.drawRect(rect)
customInit()
}
var initialized = false
func customInit() {
if !initialized {
initialized = true
trackLayer.path = UIBezierPath(roundedRect: self.bounds, cornerRadius: 15).CGPath
}
}
}
source
share