Created
January 24, 2022 22:18
-
-
Save drucelweisse/b76c5000dbf17bd5a0e9c24551f697b2 to your computer and use it in GitHub Desktop.
SwiftUI CustomTextFieldStyle example
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 | |
typealias CustomTextFieldStyle = ViewModifier | |
extension View { | |
func customTextFieldStyle<S>(_ style: S) -> some View where S: CustomTextFieldStyle { | |
modifier(style) | |
} | |
} |
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 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