textfieldswiftuicaret

SwiftUI TextField cursor colour


Currently the cursor/caret for my SwiftUI TextField is blue. Is there an API for cursor colour or a workaround?


Solution

  • EDIT: as pointed out below and in the documentation, my original answer (below) is now deprecated and you should use .tint instead. Or if you want all text fields and other UI elements in your app to be the same you can customize your app’s global accentColor.

    Original answer:

    Tried it out and .accentColor does the trick.

    TextField(" Enter some text", text: $name)
        .accentColor(.yellow)