Skip to content

Instantly share code, notes, and snippets.

@notoroid
Created March 31, 2021 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notoroid/1d2a7beb48f452a7b08a0078b7e04614 to your computer and use it in GitHub Desktop.
Save notoroid/1d2a7beb48f452a7b08a0078b7e04614 to your computer and use it in GitHub Desktop.
import SwiftUI
enum TextFieldTypes {
case defaultStyle
case customStyle
}
struct ContentView: View {
@State var myfield = ""
@ScaledMetric(relativeTo: .body) var imageSize = CGFloat(2)
@ScaledMetric(relativeTo: .body) var horizontalPadding: CGFloat = 4
@ScaledMetric(relativeTo: .body) var verticalPadding: CGFloat = 2
@ScaledMetric(relativeTo: .body) var cornerRadiusValue: CGFloat = 8
@State var textFieldTypes: TextFieldTypes = .defaultStyle
@State var text = ""
var body: some View {
VStack {
Picker("TextFieldStyle", selection: $textFieldTypes) {
Text("Original").tag(TextFieldTypes.defaultStyle)
Text("Custom").tag(TextFieldTypes.customStyle)
}
.pickerStyle(SegmentedPickerStyle())
.padding()
switch textFieldTypes {
case .defaultStyle:
HStack {
Text("DefaultTextField")
Spacer()
}.padding(.horizontal)
TextField("Label", text: $myfield)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding(.horizontal)
HStack {
Text("Plain")
Spacer()
}.padding(.horizontal)
TextField("Label", text: $myfield)
.textFieldStyle(DefaultTextFieldStyle())
.padding(.horizontal)
case .customStyle:
HStack {
Text("Rect")
Spacer()
}.padding(.horizontal)
TextField("Label", text: $myfield)
.padding(EdgeInsets(top: verticalPadding, leading: horizontalPadding, bottom: verticalPadding, trailing: horizontalPadding))
.background(
Rectangle()
.stroke(Color.gray, lineWidth: 0.333)
)
.padding(.horizontal)
HStack {
Text("RoundRect")
Spacer()
}.padding(.horizontal)
TextField("Label", text: $myfield)
.padding(EdgeInsets(top: verticalPadding,
leading: horizontalPadding + cornerRadiusValue * 0.5,
bottom: verticalPadding,
trailing: horizontalPadding + cornerRadiusValue * 0.5))
.background(
RoundedRectangle(cornerRadius: cornerRadiusValue)
.stroke(Color.gray, lineWidth: 0.333)
.foregroundColor(.clear)
)
.padding(.horizontal)
}
Spacer()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment