v5.0.0 README
v5.0.0
README
An open source package for as-you-type formatting in SwiftUI.
How to install this package.
.package(url: "https://github.com/oscbyspro/DiffableTextViews", from: "5.0.0"),
The example app provides quick-and-easy-to-use customization tools.
Download this package and compile/run it with Xcode.
A text field that binds values and formats them as you type.
environment(\.locale, _:) environment(\.layoutDirection, _:) diffableTextViews_autocorrectionDisabled(_:) diffableTextViews_font(_:) diffableTextViews_foregroundColor(_:) diffableTextViews_multilineTextAlignment(_:) diffableTextViews_onSubmit(_:) diffableTextViews_submitLabel(_:) diffableTextViews_textContentType(_:) diffableTextViews_textFieldStyle(_:) diffableTextViews_textInputAutocapitalization(_:) diffableTextViews_tint(_:) diffableTextViews_toolbarDoneButton(_:)
A style that binds localized numbers using various formats.
import DiffableTextViews import SwiftUI //*============================================================================* // MARK: * Number [...] //*============================================================================* struct ContentView: View { typealias Amount = Decimal // Decimal, Double, (U)Int(8-64), Optional<T> //=------------------------------------------------------------------------= @State var amount = 0 as Amount @State var currencyCode = "SEK" @State var locale = Locale(identifier: "sv_SE") //=------------------------------------------------------------------------= var body: some View { DiffableTextField(value: $amount) { .currency(code: currencyCode) // .bounds((0 as Amount)...) // autocorrects while view is in focus // .precision(integer: 1..., fraction: 2) // default is appropriate // .locale(Locale(identifier: "en_US")).constant() // ignores sv_SE } .environment(\.locale, locale) .diffableTextViews_font(.body.monospaced()) .diffableTextViews_keyboardType(.decimalPad) } }
A style that processes characters laid out in custom patterns.
import DiffableTextViews import SwiftUI //*============================================================================* // MARK: * Pattern [...] //*============================================================================* struct ContentView: View { typealias Number = String // Array<Character> //=------------------------------------------------------------------------= @State var number = Number("123456789") //=------------------------------------------------------------------------= var body: some View { DiffableTextField(value: $number) { .pattern("+## (###) ###-##-##") .placeholders("#") { $0.isASCII && $0.isNumber } // .hidden(true) // hides pattern beyond last real value // .equals(()) // skips comparisons and discards changes } .diffableTextViews_font(.body.monospaced()) .diffableTextViews_keyboardType(.numberPad) } }
Decorative styles that modify the behavior of their content.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
DiffableTextViews
An open source package for as-you-type formatting in SwiftUI.
Features
Installation
How to install this package.
Xcode (SPM)
Package.swift
Requirements
Apps
The example app provides quick-and-easy-to-use customization tools.
Installation
Download this package and compile/run it with Xcode.
Views
DiffableTextField
A text field that binds values and formats them as you type.
Features
Environment
Styles
NumberTextStyle (Source, Tests)
A style that binds localized numbers using various formats.
Features
Examples
PatternTextStyle (Source, Tests)
A style that processes characters laid out in custom patterns.
Features
Examples
WrapperTextStyle(s) (Source, Tests)
Decorative styles that modify the behavior of their content.