Spin Wheel Control v0.2.0
Spin Wheel Control is an inertial spinning wheel UI control that allows selection of an item. It is written in the Swift programming language can be used in iOS apps.
The code is a Swift derivation, port, and enhancement based on the Objective-C "SMWheelControl" CocoaPod written by Cesare Rocchi and Simone Civetta found here.
If you use SpinWheelControl in your app, let me know because I'd love to check it out!
Main languages and technologies used: Swift, UI Kit, Core Animation, CocoaPods, Interface Builder, Xcode
- iOS 10.0+
- Xcode 9.0+
- Swift 4.0+
To run this on your own machine:
Install Cocoapods on your machine,
Create a podfile in the project's root directory and add this line to that file within your target:
- Run pod install from the command line while inside your project's' root directory.
No extra configuration should be necessary to include this control in Swift projects.
To make this work in your Objective-C project:
In your project's (not the target's) build settings, set the Defines Module flag to YES.
Find your product module name by going to your target's (not the project's) build setting and search for Project Module Name.
Add the SpinWheelControl files to your project.
Import <productModuleName-Swift.h> in every Objective-C class you plan to use your Swift classes in. This file is automatically generated by the compiler when you include Swift classes in an Objective-C project.
Ensure the view controller containing the SpinWheelControl adheres to the SpinWheelControlDataSource and SpinWheelControlDelegate protocols:
class ViewController: UIViewController, SpinWheelControlDataSource, SpinWheelControlDelegate
Either instantiate the UIControl by dragging and dropping a SpinWheelControlView in Interface Builder and creating an IBOutlet, or instantiate the UI control with a frame via code like so:
let frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.width)
spinWheelControl = SpinWheelControl(frame: frame)
Add a target for the valueChanged event:
spinWheelControl.addTarget(self, action: #selector(spinWheelDidChangeValue), for: UIControlEvents.valueChanged)
Give the SpinWheelControl a data source:
spinWheelControl.dataSource = self
Set the SpinWheelControl's delegate:
spinWheelControl.delegate = self
Add the SpinWheelControl to your view:
Spin the wheel with a given velocity multiplier between 0 and 1 (defaults to 0.75)
Randomly spin the wheel:
Data Source Methods
The following data source methods are available:
//Specify the number of wedges in the spin wheel by returning a positive value that is greater than 1
func numberOfWedgesInSpinWheel(spinWheel: SpinWheelControl) -> UInt
//Returns the SpinWheelWedge at the specified index of the SpinWheelControl
func wedgeForSliceAtIndex(index: UInt) -> SpinWheelWedge
The following delegate methods are available:
//Triggered when the spin wheel control has come to rest after spinning.
func spinWheelDidEndDecelerating(spinWheel: SpinWheelControl)
//Triggered at various intervals. The variable radians describes how many radians the spin wheel control has moved since the last time this method was called.
func spinWheelDidRotateByRadians(radians: CGFloat)
The following properties are available for modification:
borderWidth - The width of the border around the spin wheel
borderColor - The color of the border around the spin wheel
cornerRadius - Set with a CGFloat value to round the edges of the border around the spin wheel
snapOrientation - The direction in which the wheel "snaps" (SpinWheelDirection.up, SpinWheelDirection.right, SpinWheelDirection.down, or SpinWheelDirection.left)
wedgeLabelOrientation - The orientation of labels in each wedge (WedgeLabelOrientation.inOut or WedgeLabelOrientation.around)
To see SpinWheelControl in action, open the example project in the SpinWheelExample folder.
Josh Henry - Big Smash Software
Based on the Objective-C "SMWheelControl" CocoaPod written by Cesare Rocchi and Simone Civetta found here.