I need to be able to style TextField in my SwiftUI macOS application. Specifically, I would need to be able to change the cursor (caret) and the selection color. As I read online, for this people use either older and marked for deprecation .accentColor() function or newer .tint() function. However, it seems like the application simply ignores those functions.
struct ContentView: View { @State private var text = "" var body: some View { VStack { TextField("Text field", text: $text) .tint(.red) } .padding() } } This code produces this window. As you can see .tint(.red) is being ignored and orange system Accent Color is being used.
I've tried using older and marked for deprecation .accentColor() - it didn't work. Tried making custom style for TextField and setting .tint()/.accentColor() there - same result.
I'm on macOS 14.6.1 (23G93) and using Xcode version 16.0 (16A242d)
Did I somehow set up the project incorrectly? Or there's something that I am missing here?
EDIT (17.09.24 20:25): I found this answer that suggested subclassing NSTextField. I'd personally like to avoid doing that as it'd require me to reimplement some properties of TextField and it breaks .style(), which I use to apply custom look to the TextField. Also, currently, if I'd want to pass a theme to the init function of that custom NSTextField, it'd ask me to implement other constructors (including init(frame:) without which the app just crashes, even though Xcode isn't saying anything about it).

Tint works
*Accent color does not *