Common Textfield Style (CommonTextField()
)
For your Textfields to have a common appearance, we include a textifeld style called CommonTextField()
.
Simply attach it to your textfield to give it a consistent look.
Definition
CommonTextField.swift
public struct CommonTextField: TextFieldStyle {
public init(disabled: Bool = false) {
self.disabled = disabled
}
}
disabled
(Optional): A boolean value to determine if the textfield is disabled or not. Default isfalse
.
Usage Example
VStack (spacing: 20) {
TextField("Test TextField", text: .constant("Hello"))
.textFieldStyle(CommonTextField())
TextField("Test TextField", text: .constant("Hello"))
.textFieldStyle(CommonTextField(disabled: true))
}
Styling
You can additionally change the default height, radius and font of the the textfield
by editing the constants values on top of the CommonTextField.swift
file.
CommonTextField.swift
let commonTextFieldRadius = 10.0
let commonTextFieldHeight = 50.0
let commonTextFieldFontStyle: Font = .system(.body, weight: .regular)