A floating label style for TextField
with support for displaying error messages.
- iOS 15.0+
- macOS 12.0+
dependencies: [
.package(url: "https://github.com/reddavis/FloatingLabelTextFieldStyle", from: "0.9.0")
]
import FloatingLabelTextFieldStyle
import SwiftUI
struct ContentView: View
{
@State var email = ""
// MARK: Body
var body: some View {
VStack {
TextField("e.g. [email protected]", text: self.$email)
.textFieldStyle(
.floating(
titleStyle: .init(text: "Email")
)
)
TextField("e.g. [email protected]", text: .constant("💩"))
.textFieldStyle(
.floating(
borderColor: .red,
titleStyle: .init(text: "Email"),
errorStyle: .init(text: "💩 is not a valid email address.")
)
)
}
.padding()
}
}
Whatevs.