Answers for "set placeholder text color swift"

2

change textfield placeholder color swiftui

//- Custom TextField
// You can always create your own custom Views to use everywhere:

struct CustomTextField: View {
    var placeholder: Text
    @Binding var text: String
    var editingChanged: (Bool)->() = { _ in }
    var commit: ()->() = { }

    var body: some View {
        ZStack(alignment: .leading) {
            if text.isEmpty { placeholder }
            TextField("", text: $text, onEditingChanged: editingChanged, onCommit: commit)
        }
    }
}

// usage (TextField with placeholder):

struct ContentView: View {
    @State var text = ""

    var body: some View {
        CustomTextField(
            placeholder: Text("placeholder").foregroundColor(.red),
            text: $text
        )
    }
}
Posted by: Guest on March-13-2020
0

change placeholder color swift

myTextField.attributedPlaceholder = NSAttributedString(string: "placeholder text",
                             attributes: [NSAttributedString.Key.foregroundColor: UIColor.white])
Posted by: Guest on March-04-2020

Code answers related to "set placeholder text color swift"

Code answers related to "Swift"

Browse Popular Code Answers by Language