Created
February 19, 2021 01:17
-
-
Save mattyoung/ce637cd189468f05170ac002fb78081c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 SwiftUI | |
| struct ContentView: View { | |
| @State var value = -122.90 | |
| let range = -300.0...300 | |
| var body: some View { | |
| VStack { | |
| #warning("`alignment: .firstTextBaseline`, cause the Text inside Label is elided sometime") | |
| HStack(alignment: .firstTextBaseline) { | |
| Label("Temperature", systemImage: "thermometer") | |
| Text("\(value, specifier: "%.2f")") | |
| .font(.title) | |
| } | |
| // if these modifiers are commented out, no elide problem | |
| .padding() | |
| .background(Color.gray) | |
| .cornerRadius(10.0) | |
| .border(Color.green) | |
| HStack(alignment: .lastTextBaseline) { | |
| Label("Temperature", systemImage: "thermometer") | |
| Text("\(value, specifier: "%.2f")") | |
| .font(.title) | |
| } | |
| .padding() | |
| .background(Color.gray) | |
| .cornerRadius(10.0) | |
| .border(Color.green) | |
| HStack(alignment: .top) { | |
| Label("Temperature", systemImage: "thermometer") | |
| Text("\(value, specifier: "%.2f")") | |
| .font(.title) | |
| } | |
| .padding() | |
| .background(Color.gray) | |
| .cornerRadius(10.0) | |
| .border(Color.green) | |
| HStack { | |
| Label("Temperature", systemImage: "thermometer") | |
| Text("\(value, specifier: "%.2f")") | |
| .font(.title) | |
| } | |
| .padding() | |
| .background(Color.gray) | |
| .cornerRadius(10.0) | |
| .border(Color.green) | |
| #warning("Add .fixedSize() to Label fix the problem, but it's not ideal") | |
| HStack { | |
| Label("Temperature", systemImage: "thermometer") | |
| .fixedSize() | |
| Text("\(value, specifier: "%.2f")") | |
| .font(.title) | |
| } | |
| .padding() | |
| .background(Color.gray) | |
| .cornerRadius(10.0) | |
| .border(Color.green) | |
| Spacer() | |
| Slider(value: $value, in: range, | |
| step: 0.1, | |
| minimumValueLabel: Text("\(range.lowerBound, specifier: "%.2f")"), | |
| maximumValueLabel: Text("\(range.upperBound, specifier: "%.2f")"), | |
| label: { Text("Value") }) | |
| } | |
| } | |
| } | |
| struct ContentView_Previews: PreviewProvider { | |
| static var previews: some View { | |
| ContentView() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment