Skip to content

Instantly share code, notes, and snippets.

@drucelweisse
Created January 24, 2022 22:18
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 drucelweisse/b76c5000dbf17bd5a0e9c24551f697b2 to your computer and use it in GitHub Desktop.
Save drucelweisse/b76c5000dbf17bd5a0e9c24551f697b2 to your computer and use it in GitHub Desktop.
SwiftUI CustomTextFieldStyle example
import SwiftUI
typealias CustomTextFieldStyle = ViewModifier
extension View {
func customTextFieldStyle<S>(_ style: S) -> some View where S: CustomTextFieldStyle {
modifier(style)
}
}
import SwiftUI
struct LargeTextFieldStyle: CustomTextFieldStyle {
func body(content: Content) -> some View {
VStack(spacing: 2) {
content
.font(font)
.disableAutocorrection(true)
.autocapitalization(.words)
Rectangle().foregroundColor(Color.blue).frame(maxWidth: .infinity, maxHeight: 2)
}
}
let font: Font = Font.system(size: 26, weight: .bold)
}
extension CustomTextFieldStyle where Self == LargeTextFieldStyle {
static var large: LargeTextFieldStyle { LargeTextFieldStyle() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment