Knob

open class Knob : UIControl

Custom UIControl that depicts a value as a point on a circle. Changing the value is done by touching on the control and moving up to increase and down to decrease the current value. While touching, moving away from the control in either direction will increase the resolution of the touch changes, causing the value to change more slowly as vertical distance changes. Pretty much works like UISlider but with the travel path as an arc.

Visual representation of the knob is done via CoreAnimation components, namely CAShapeLayer and UIBezierPath. The diameter of the arc of the knob is defined by the min(width, height) of the view’s frame. The start and end of the arc is controlled by the startAngle and endAngle settings.

  • The minimum value reported by the control.

    Declaration

    Swift

    open var minimumValue: Float { get set }
  • The maximum value reported by the control.

    Declaration

    Swift

    open var maximumValue: Float { get set }
  • The current value of the control.

    Declaration

    Swift

    open var value: Float { get set }
  • How much travel is need to move 4x the width or height of the knob to go from minimumValue to maximumValue. By default this is 4x the knob size.

    Declaration

    Swift

    open var touchSensitivity: Float
  • The width of the arc that is shown after the current value.

    Declaration

    Swift

    open var trackLineWidth: CGFloat { get set }
  • The color of the arc shown after the current value.

    Declaration

    Swift

    open var trackColor: UIColor { get set }
  • The width of the arc from the start up to the current value.

    Declaration

    Swift

    open var progressLineWidth: CGFloat { get set }
  • The color of the arc from the start up to the current value.

    Declaration

    Swift

    open var progressColor: UIColor { get set }
  • The width of the radial line drawn from the current value on the arc towards the arc center.

    Declaration

    Swift

    open var indicatorLineWidth: CGFloat { get set }
  • The color of the radial line drawn from the current value on the arc towards the arc center.

    Declaration

    Swift

    open var indicatorColor: UIColor { get set }
  • The proportion of the radial line drawn from the current value on the arc towards the arc center. Range is from 0.0 to 1.0, where 1.0 will draw a complete line, and anything less will draw that fraction of it starting from the arc.

    Declaration

    Swift

    open var indicatorLineLength: CGFloat { get set }
  • The width of the radial line drawn from the current value on the arc to the arc center.

    Declaration

    Swift

    open var radialLineWidth: CGFloat { get set }
  • The color of the radial line drawn from the current value on the arc towards the arc center.

    Declaration

    Swift

    open var radialLineColor: UIColor { get set }
  • The proportion of the radial line drawn from the current value on the arc towards the arc center. Range is from 0.0 to 1.0, where 1.0 will draw a complete line, and anything less will draw that fraction of it starting from the arc.

    Declaration

    Swift

    open var radialLineLength: CGFloat { get set }
  • Number of ticks to show inside the track, with the first indicating the minimumValue and the last indicating the maximumValue

    Declaration

    Swift

    open var tickCount: Int { get set }
  • Length of the tick. Range is from 0.0 to 1.0 where 1.0 will draw a line ending at the center of the knob.

    Declaration

    Swift

    open var tickLineLength: CGFloat { get set }
  • The width of the tick line.

    Declaration

    Swift

    open var tickLineWidth: CGFloat { get set }
  • The color of the tick line.

    Declaration

    Swift

    open var tickLineColor: UIColor { get set }
  • The starting angle of the arc where a value of 0.0 is located. Arc angles are explained in the UIBezier documentation for init(arcCenter:radius:startAngle:endAngle:clockwise:). In short, a value of 0.0 will start on the positive X axis, a positive PI/2 will lie on the negative Y axis. The default values will leave a small gap at the bottom.

    Declaration

    Swift

    open var startAngle: Float { get set }
  • The ending angle of the arc where a value of 1.0 is located. See startAngle for additional info.

    Declaration

    Swift

    open var endAngle: Float { get set }
  • Construction from an encoded representation.

    Declaration

    Swift

    public required init?(coder aDecoder: NSCoder)

    Parameters

    aDecoder

    the representation to use

  • Construct a new instance with the given location and size. A knob will take the size of the smaller of width and height dimensions given in the frame parameter.

    Declaration

    Swift

    public override init(frame: CGRect)

    Parameters

    frame

    geometry of the new knob

  • Reposition layers to reflect new size.

    Declaration

    Swift

    public override func layoutSubviews()
  • Set the knob value.

    Declaration

    Swift

    public func setValue(_ value: Float, animated: Bool = false)

    Parameters

    value

    the new value to use

    animated

    if true, animate the view as it shows the new value

  • Begin tracking a touch event in the knob.

    Declaration

    Swift

    override open func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool

    Parameters

    touch

    the touch event that took place

    event

    the event that generated the touch

  • Continue tracking a touch event in the knob.

    Declaration

    Swift

    override open func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool

    Parameters

    touch

    the updated touch event

    event

    the event that generated the touch

  • Cancel a touch event. NOTE: this does not reset the knob to the original value.

    Declaration

    Swift

    override open func cancelTracking(with event: UIEvent?)

    Parameters

    event

    the event that generated the touch

  • End tracking a touch event in the knob.

    Declaration

    Swift

    override open func endTracking(_ touch: UITouch?, with event: UIEvent?)

    Parameters

    touch

    the updated touch event

    event

    the event that generated the touch