Skip to content

An easy to use, drop-in, reusable UI component built in Swift to display a horizontal number picker.

License

Notifications You must be signed in to change notification settings

xanderbuck/MILRatingCollectionView

 
 

Repository files navigation

MILRatingCollectionView

Drawing

MILRatingCollectionView is an easy to use, drop-in, reusable UI component built in Swift to display a horizontal number picker. It has a customizable number range and font so you can display a beautiful number picker, however you like.

Installation

Simply copy MILRatingCollectionView.swift into your Xcode project.

Usage

Open ViewControllerExample.swift to see an example in context.

  1. Create a UICollectionView in storyboard or in code and position it however you like.

  2. Optionally, in the viewDidLoad of your viewController, set the background color of the centered circle. In this example, milRatingCollectionView is an instance of MILRatingCollectionView

     milRatingCollectionView.circularView.backgroundColor = UIColor.redColor()
    
  3. Optionally, you can specify the number range to display using an NSRange. Where .location is the starting point and .length is the number to end on + 1. For example,

     milRatingCollectionView.numberRange = NSMakeRange(1, 11) // 1 to 10 range
    

The default range is 0 to 10 if numberRange isn't set.

  1. If desired, you can change the font name from Helvetica to whatever you like, assuming there is a Medium and Bold version of that font. You can change the font at line 251 of MILRatingCollectionView.swift,

     let selectedFont = "Helvetica"
    

Customizable Properties

Property Descriptions
constants.numCellsVisible: CGFloat Number of cells visible at a time in the view. Even values will show one less cell than selected on startup, due to the view being centered on an initial value. Default is 5
constants.minCellWidthInPixels: CGFloat The minimum number of pixels each cell should be. Does not usually need be changed. Only takes effect when the numCellsVisible is set to a value that leaves little room for each cell. Default is 45
constants.circleDiameterToViewHeightRatio: CGFloat The diameter of the circle relative to the height of the cell. Default is 0.6
constants.circleBackgroundColor: UIColor The background color of the circle that surrounds the selected item. Default is rgb(218, 87, 68)
constants.numberRange: NSRange The range of the collectionView, location is the starting number, length is the number of elements. Default is NSMakeRange(0,11)

Requirements

  • Currently, MILRatingCollectionView is set up to work with iOS 8+
  • It may take a small amount of adjustment to work on iOS 7

Author

Created by Taylor Franklin (tfrank64) at the IBM Mobile Innovation Lab

License

MILRatingCollectionView is available under the Apache 2.0 license. See the LICENSE file for more info.

Sample App License

The PickerTest sample application is available under the Apple SDK Sample Code License. Details in the file called SAMPLE_APP_LICENSE under the Example directory.

About

An easy to use, drop-in, reusable UI component built in Swift to display a horizontal number picker.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%