iOS 8.0
The easiest way to use HSBColorWheelPicker is with CocoaPods. Add the following line to your Podfile.
pod "HSBColorWheelPicker"
Otherwise you need to include the following files into your project:
ColorWheel.swift
ColorView.swift
HSBColorWheelPicker is optimized for Interface Builder and AutoLayout.
- On the storyboard drag an UIView into a View Controller.
- Set HSBColorWheel as class of UIView.
- On the ViewController implmentation import the HSBColorWheelPicker framework.
- Make a connection between HSBColorWheel view and View Controller.
- Implement the HSBColorWheelDelegate protocol on the View Controller. Just only one method: colorWheel(_ colorWheel:HSBColorWheel, didSelectColor color:UIColor)
- Set View Controller as delegate of HSBColorWheel view
- Ready to use it.
You can customize the user interface changing the following values
- @IBInspectable public var colorSize:CGFloat
- @IBInspectable public var wheelDivisions:Int
- @IBInspectable public var colorSeparation:CGFloat
- @IBInspectable public var showWheelEdge:Bool
- @IBInspectable public var wheelEdgeColor:UIColor
- @IBInspectable public var wheelEdgeWidth:CGFloat
- @IBInspectable public var showDivisions:Bool
- @IBInspectable public var divisionsColor:UIColor
- @IBInspectable public var divisionsWidth:CGFloat
- @IBInspectable public var showColorEdge:UIColor
- @IBInspectable public var colorEdgeWidth:CGFloat
- @IBInspectable public var colorEdgeColor:UIColor
- @IBInspectable public var showSelectedColor:Bool
As shown below, you can also programmatically customize HSBColorWheelPicker
let frame = CGRect(x: 0, y: 0, width: 320, height: 320)
let colorWheel = HSBColorWheel(frame: frame)
colorWheel.colorSize = 33
colorWheel.wheelDivisions = 11
colorWheel.colorSeparation = 2
colorWheel.showWheelEdge = true
colorWheel.showDivisions = true
colorWheel.showColorEdge = true
view.addSubview(colorWheel)
- colorSize = 20
- wheelDivisions = 4
- colorSeparation = 1
- showWheelEdge = false
- wheelEdgeColor = black
- wheelEdgeWidth = 1.0
- showDivisions = false
- divisionsColor = black
- divisionsWidth = 1.0
- showColorEdge = true
- colorEdgeWidth = 0.5
- colorEdgeColor = black
- showSelectedColor = true
Change values using Interface Builder
Color wheel with edge and division lines
Color wheel without edge and division lines
- Separation lines width: 20dp
- Separation lines color: black with 0.5 alpha
- Separation lines width: 35dp
- Separation lines color: black with 0.75 alpha
Patricio Aguirre - me@patoman007.com - @patoman007
HSBColorWheelPicker is available under the MIT license. See the LICENSE file for more info.