Change UITextField and UITextView Cursor / Caret Color

前端 未结 16 2029
醉话见心
醉话见心 2020-12-07 09:33

I\'m wondering about changing the color of the cursor / caret in a UITextField (And UITextView if its the same answer) in iOS. I\'ve seen answers f

相关标签:
16条回答
  • 2020-12-07 09:35

    For people searching the equivalent in SwiftUI for Textfield this is accentColor:

    TextField("Label", text: $self.textToBind).accentColor(Color.red)
    
    0 讨论(0)
  • 2020-12-07 09:37

    With iOS7 you can simply change tintColor of the textField

    0 讨论(0)
  • 2020-12-07 09:38

    If you're targeting iOS 7+, this has been made much easier. Simply change the tintColor of the field with a cursor using the appearance proxy and it will apply throughout the app:

    Swift 3.0:

    UITextField.appearance().tintColor = .black 
    

    Objective-C:

    [[UITextField appearance] setTintColor:[UIColor blackColor]];
    

    Same answer applies for an individual UITextField:

    Swift 3.0:

    myTextField.tintColor = .black 
    

    Objective-C

    [myTextField setTintColor:[UIColor blackColor]];
    
    0 讨论(0)
  • 2020-12-07 09:40

    Swift 4

    In viewDidLoad() just call below code:

    CODE SAMPLE

    //txtVComplaint is a textView
    
    txtVComplaint.tintColor = UIColor.white
    
    txtVComplaint.tintColorDidChange()
    
    0 讨论(0)
  • 2020-12-07 09:41

    This worked for me in swift:

    UITextField.tintColor = UIColor.blackColor()
    

    You can also set this in storyboard: https://stackoverflow.com/a/18759577/3075340

    0 讨论(0)
  • 2020-12-07 09:41

    Try, Its working for me.

    [[self.textField valueForKey:@"textInputTraits"] setValue:[UIColor redColor] strong textforKey:@"insertionPointColor"];
    
    0 讨论(0)
提交回复
热议问题