https://github.com/mattlewin/numericpicker
iOS picker for easily selecting numbers by digit. (Swift)
https://github.com/mattlewin/numericpicker
accessibility carthage cocoapods dynamic-font ios numeric picker pickerview swift swift-4 swift4
Last synced: about 2 months ago
JSON representation
iOS picker for easily selecting numbers by digit. (Swift)
- Host: GitHub
- URL: https://github.com/mattlewin/numericpicker
- Owner: MattLewin
- License: mit
- Created: 2017-02-09T23:42:23.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2018-10-10T02:33:29.000Z (over 6 years ago)
- Last Synced: 2025-04-08T23:17:49.064Z (about 2 months ago)
- Topics: accessibility, carthage, cocoapods, dynamic-font, ios, numeric, picker, pickerview, swift, swift-4, swift4
- Language: Swift
- Homepage:
- Size: 227 KB
- Stars: 18
- Watchers: 1
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# NumericPicker
[](http://cocoapods.org/pods/NumericPicker)
[](http://cocoapods.org/pods/NumericPicker)
[](http://cocoapods.org/pods/NumericPicker)
[](https://swift.org)
[](https://travis-ci.org/MattLewin/NumericPicker)[](https://cocoapods.org/pods/NumericPicker)
[](https://github.com/Carthage/Carthage)
[](https://swift.org/package-manager/)[](https://github.com/MattLewin/NumericPicker/releases)
## Description
NumericPicker is a drop-in iOS picker control written in Swift. It simplifies the creation of pickers that allow
your users to specify numbers by digit. It automatically uses the proper grouping and decimal separator for the
current (or specified) locale. You can easily dictate the number of integer and decimal places in the controller.
*Note that the "Picker Value" field is there for demonstration purposes only. It is not included in the
`NumericPicker` control.*---
## Table of Contents
* [Example](#example)
* [Minimum Requirements](#minimum-requirements)
* [Installation](#installation)
* [Usage](#usage)
* [Author](#author)
* [License](#license)---
## Minimum Requirements
### Version 1.1.x
* Xcode 10
* iOS 10.3
* Swift 4.2### Version 1.0.x
* Xcode 9
* iOS 10.3## Example
This repo contains an example project demonstrating how to use the `NumericPicker` control from Interface Builder and
from code.To run the example project, clone the repo, open `NumericPicker.xcodeproj` and run the `NumericPicker-Example` scheme
## Installation
### CocoaPods
NumericPicker is available through [CocoaPods](http://cocoapods.org).
[CocoaPods](http://cocoapods.org) is a dependency manager for Swift and Objective-C that simplifies the use of 3rd-party
libraries like `NumericPicker` in your projects.First, add the following line to your [Podfile](http://guides.cocoapods.org/using/using-cocoapods.html):
```ruby
pod "NumericPicker"
```or, for Xcode 9 and Swift 4.0
```ruby
pod "NumericPicker", '~> 1.0.0'
```Second, install `NumericPicker` into your project:
```bash
pod install
```### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and
provides you with binary frameworks.To integrate `NumericPicker` into your Xcode project using Carthage, specify it in your `Cartfile`:
```ruby
github "MattLewin/NumericPicker"
```or, for Xcode 9 and Swift 4.0
```ruby
github "MattLewin/NumericPicker" ~> 1.0.0
```Run `carthage update` to build the framework and drag the built `NumericPicker.framework` (in Carthage/Build/iOS folder)
into your Xcode project (Linked Frameworks and Libraries in `Targets`).### Swift Package Manager (SPM)
The [Swift Package Manager](https://github.com/apple/swift-package-manager) does not yet support importing `UIKit` or compilation for
`iOS`. Thus, `NumericPicker` can not yet be used with the SPM.### Manually
1. Copy `NumericPicker.swift` into your project
2. Have a nice day## Usage
`NumericPicker` is a subclass of [`UIControl`](https://developer.apple.com/reference/uikit/uicontrol). In this way it
is more like [`UIDatePicker`](https://developer.apple.com/reference/uikit/uidatepicker) than it is like
[`UIPickerView`](https://developer.apple.com/reference/uikit/uipickerview). What this means for you is that you don't
need to implement [`UIPickerViewDataSource`](https://developer.apple.com/reference/uikit/uipickerviewdatasource) or
[`UIPickerViewDelegate`](https://developer.apple.com/reference/uikit/uipickerviewdelegate).*Note that the provided [Example](#example) demonstrates everything detailed below.*
### Configurable Properties
* `value: Double` - The value displayed in the picker. Set this value to update the picker programatically.
*(Default: 0)*
* `minIntegerDigits: Int` - The minimum number of integer digits (digits to the left of the decimal separator) to
include in the picker. Think of this as zero-padding the picker. If `value` requires more than this minimum, the picker
will automatically meet this requirement. (This is probably not what you want, though.) *(Default: 1)*
* `fractionDigits: Int` - The number of digits to the right of the decimal separator. `NumericPicker` guarantees
exactly this many fractional digits will be displayed. You can use this to achieve rounding or zero-padding of values
to the right of the decimal separator. *(Default: 0)*
* `locale: Locale` - The locale used to format the numeric values. Use this if you want numbers formatted with
separators other than those used by the device locale. *(Default: current device locale)*
* `font: UIFont` - The font used to format the picker components. *(Default: `Body` text style)*
* `displayString: String` - **READ ONLY** - The text representation of `value`. This string will contain locale-specific
grouping and decimal separators. It will have exactly `fractionDigits` digits to the right of the decimal separator and
the minimum number of integer places necessary to represent `value`.### Interface Builder
To use `NumericPicker` with Interface Builder, add a [`UIControl`](https://developer.apple.com/reference/uikit/uicontrol)
to your storyboard or XIB, and then set the "Custom Class" to `NumericPicker`. Connect the "`Value Changed`" event to
a function in your view controller. (Be certain to set the "Type" to `NumericPicker` as shown below.)
Within that function, you can access `sender.displayString` or `sender.value` as needed.
#### *Cocoapods or Manually*
If you are using Cocoapods or have dropped `NumericPicker.swift` into your code, you can configure `value`,
`minIntegerDigits`, and `fractionDigits` from the "Attributes" inspector.
#### *Carthage*
Xcode does not currently (as of 9.0) support `@IBInspectable` properties from external frameworks. The means
you cannot configure the above properties in IB. You can, however, trick IB into rendering `NumericPicker` with its
default values by adding the following code to one of your view controllers:```swift
@IBDesignable extension NumericPicker { }
```### Code
Add a `NumericPicker` control from code as you would any other subview. Here is the code from
`NumericPicker-Example/ViewController.swift` to produce the bottom sample `NumericPicker`. Note that it is typically unnecessary
to set `locale`, as `NumericPicker` will use the current device locale by default.```swift
var codeNumericPicker = NumericPicker()
codeNumericPicker.minIntegerDigits = 6
codeNumericPicker.fractionDigits = 3
codeNumericPicker.value = 76543.21
codeNumericPicker.locale = Locale(identifier: "de-DE")
codeNumericPicker.addTarget(self, action: #selector(codeValueChanged), for: .valueChanged)
codePickerStack.addArrangedSubview(codeNumericPicker)```
## Author
Matt Lewin, [email protected]
## License
NumericPicker is available under the MIT license. See [LICENSE.md](https://raw.githubusercontent.com/MattLewin/NumericPicker/master/LICENSE.md)
for more info.