A floating label style for TextField with support for displaying error messages

FloatingLabelTextFieldStyle

A floating label style for TextField with support for displaying error messages.

Requirements

  • iOS 15.0+
  • macOS 12.0+

Installation

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/reddavis/FloatingLabelTextFieldStyle", from: "0.9.0")
]

Usage

import FloatingLabelTextFieldStyle
import SwiftUI


struct ContentView: View
{
    @State var email = ""
    
    // MARK: Body
    
    var body: some View {
        VStack {
            TextField("e.g. me@red.to", text: self.$email)
                .textFieldStyle(
                    .floating(
                        titleStyle: .init(text: "Email")
                    )
                )
            
            TextField("e.g. me@red.to", text: .constant("?"))
                .textFieldStyle(
                    .floating(
                        borderColor: .red,
                        titleStyle: .init(text: "Email"),
                        errorStyle: .init(text: "? is not a valid email address.")
                    )
                )
        }
        .padding()
    }
}

License

Whatevs.

GitHub

https://github.com/reddavis/FloatingLabelTextFieldStyle