Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.34 KB

README.md

File metadata and controls

55 lines (42 loc) · 1.34 KB

UnitNumberField

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.

Screenshot

Features

  • 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

Installation

Add https://github.com/Maschina/UnitNumberField in the “Swift Package Manager” tab in Xcode.

Requirements

macOS 10.15+

Usage

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)