Swiftpack.co - Package - dongyaxun/Knob

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

dongyaxun/Knob

A knob UIControl in Swift.

Knob

A knob UIControl in Swift.

indicator

Usage

Initialization

let knob = Knob(frame: CGRect(x: (view.bounds.width - 240) / 2,
                              y: (view.bounds.height - 240) / 2,
                              width: 240,
                              height: 240))
view.addSubview(knob)

Action

  • set value
knob.setValue(targetValue, animated: true)
  • add target
knob.addTarget(self, action: #selector(ViewController.handleValueChanged(_:)), for: .valueChanged)
  • handle value changed
@objc func handleValueChanged(_ sender: Knob) {
    print("value: \(sender.value)")
}

Configuration

  • value range
knob.minimumValue = 0
knob.maximumValue = 260
  • angle range
knob.startAngle = -CGFloat.pi * 5 / 4
knob.endAngle = CGFloat.pi / 4
  • graduations
knob.graduations = 26
knob.largeGraduations = 13
  • value dispaly
knob.valueDisplay = .forLargeGraduation
knob.valueAttributes = [.foregroundColor: UIColor.black, .font: UIFont.systemFont(ofSize: 16) ]
knob.valueFormatter = { "\(Int($0))" }
  • indicator type
knob.indicatorType = .pointer(color: .red, length: 100, width: 4)
  • other configurations
knob.isEnableFeedback = true
knob.isGraduationsAligned = true
knob.isContinuous = true

Features

  • ☑ Multiple indicators
  • ☑ Controlled Angle Range
  • ☑ Display Graduations
  • ☑ Support Storyboard
  • ☐ Custom indicator layer

Requirements

  • iOS 10.0+
  • Swift 5.0+

Installation

CocoaPods

pod 'Knob', '~> 0.0.1'

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/dongyaxun/Knob.git", .upToNextMajor(from: "0.0.1"))
]

License

Knob is released under the MIT license. See LICENSE for details.

Github

link
Stars: 0
Last commit: 1 week ago