This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import SwiftUI | |
struct FormatterView: View { | |
@State var limits: TemperatureLimits | |
var body: some View { | |
VStack(spacing: 16) { | |
VStack { | |
Text("Low") | |
NumberTextField("Low", value: $limits.lowNumber, formatter: NumberFormatter.decimal) | |
} | |
VStack { | |
Text("High") | |
NumberTextField("High", value: $limits.highNumber, formatter: NumberFormatter.decimal) | |
} | |
Button(action: { | |
self.limits.low = Int.random(in: 0...40) | |
self.limits.high = Int.random(in: 50...100) | |
}, label: { | |
Text("Randomise") | |
}) | |
Text("Current: \(limits.low) - \(limits.high)") | |
Spacer() | |
}.padding() | |
.multilineTextAlignment(.center) | |
} | |
} | |
extension NumberFormatter { | |
static var decimal: NumberFormatter { | |
let formatter = NumberFormatter() | |
formatter.allowsFloats = false | |
return formatter | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment