A customized text field for unit-based number input for SwiftUI and AppKit (macOS). Allows user to input numbers only and validates it, respectively. Similar to the input field in Sketch.
- Compatibility to SwiftUI and AppKit (macOS)
- Available for Double values only at the moment
- Inline label for unit
- Feedback closure if input is not valid
- Range control (clamp the given input to a certain range)
- Formatter control (validate the input towards a given formatter)
- Bezel style support
- Control size support
Add https://github.com/Maschina/UnitNumberField in the “Swift Package Manager” tab in Xcode.
macOS 10.15+
Example for usage in SwiftUI with units:
UnitNumberField(
value: proxy,
unitText: "°",
range: 0...360,
formatter: NumberFormatter.doubleFormatter(digits: 0),
bezelStyle: .roundedBezel,
controlSize: .small
)
.frame(width: 55)
Example for usage in SwiftUI without units:
UnitNumberField(
value: proxy,
unitText: nil,
range: 0...360,
formatter: NumberFormatter.doubleFormatter(digits: 0),
bezelStyle: .roundedBezel,
controlSize: .small
)
.frame(width: 55)