TTBaseSUITextField
SwiftUI CoreSwiftUI text field with 4 border types (DEFAULT, NO_BORDER, ONLY_BOTTOM, NO_PADDING), secure/password mode, disabled state, placeholder styling, and real-time text change handler. Mirrors the UIKit TTBaseUITextField API in SwiftUI idiom.
🎨 Types
public enum TYPE {
case DEFAULT // Rounded rect border
case NO_BORDER // No visible border
case ONLY_BOTTOM // Bottom underline only
case NO_PADDING // Zero padding, no border
}
| Type | Appearance | Use Case |
|---|---|---|
.DEFAULT | Rounded border | Standard form fields |
.NO_BORDER | No border | Fields inside custom containers |
.ONLY_BOTTOM | Bottom line | Flat/modern style |
.NO_PADDING | Minimal | Tight layouts |
🚀 Usage
// Standard text field with binding
@State private var name = ""
TTBaseSUITextField(
text: $name,
placeholder: "Enter your name"
)
// Secure password field
@State private var password = ""
TTBaseSUITextField(
text: $password,
placeholder: "Password",
isSecure: true
)
// Bottom-line style (flat form)
TTBaseSUITextField(
text: $email,
placeholder: "Email address",
type: .ONLY_BOTTOM
)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)
// Disabled field (read-only display)
TTBaseSUITextField(
text: $userId,
placeholder: "",
isDisabled: true
)
// Real-time text change handler
TTBaseSUITextField(text: $query, placeholder: "Search...")
.onChange(of: query) { newValue in
viewModel.search(newValue)
}
🏗 In a Login Form
struct LoginView: View {
@State private var email = ""
@State private var password = ""
var body: some View {
VStack(spacing: 16) {
TTBaseSUITextField(
text: $email,
placeholder: "Email",
type: .ONLY_BOTTOM
)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)
TTBaseSUITextField(
text: $password,
placeholder: "Password",
type: .ONLY_BOTTOM,
isSecure: true
)
.textContentType(.password)
TTBaseSUIButton(text: "Sign In") {
login(email: email, password: password)
}
}
.padding()
}
}
📖 Initializer Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
text | Binding<String> | — | Two-way text binding |
placeholder | String | "" | Placeholder text |
type | TYPE | .DEFAULT | Border style |
isSecure | Bool | false | Enable password masking |
isDisabled | Bool | false | Make field read-only/grayed |
Pro Tip: For a password toggle (show/hide), layer
TTBaseSUITextField(isSecure: !showPassword) with a Button toggling showPassword using SwiftUI's native overlay API.