I was trying to follow this tutorial on building a custom control in iOS: http://www.raywenderlich.com/36288/how-to-make-a-custom-control
I wanted to then try out the @IBDesignable and @IBInspectable properties to see how live rendering worked so I exposed those. I then dropped a UIView on my storyboard and changed the class to the RangeSlider and although it looks ok in the Assistant Editor's preview mode, when I run it in the simulator, it does not actually render the two thumbLayers. When I set a breakpoint in my code, I see that even though setNeedsDisplay is called for the different layers of the custom control, the actual drawInContext methods are never called. To try to reproduce this, I created these two files and the same thing happens, no drawInContext ever gets called.
TestControl.swift
import UIKit
@IBDesignable
class TestControl: UIControl {
@IBInspectable var cornerRadius: CGFloat = 3.0 {
didSet {
updateLayerFrames()
}
}
let testLayer = TestLayer()
override var frame: CGRect {
didSet {
updateLayerFrames()
}
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// testLayer.contentsScale = UIScreen.mainScreen().scale
// layer.addSublayer(testLayer)
}
override init(frame: CGRect) {
super.init(frame: frame)
testLayer.contentsScale = UIScreen.mainScreen().scale
layer.addSublayer(testLayer)
}
func updateLayerFrames() {
CATransaction.begin()
CATransaction.setDisableActions(true)
testLayer.setNeedsDisplay()
CATransaction.commit()
}
}
TestLayer.swift
import UIKit
import QuartzCore
class TestLayer: CALayer {
override func drawInContext(ctx: CGContext!) {
println("test test")
}
}
ViewController.swift
@IBOutlet var testControl: TestControl!
Is there something I'm missing about the process of creating a custom control? Sorry if this is a noob question.