Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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