-1

It's seen in UITextView and UITextField - the flashing blue line which shows you where anything you type will be typed. I've seen some apps change the color of this and wasn't sure how to do that. How do I change it's color?

Andrew
  • 15,489
  • 25
  • 116
  • 200
  • 1
    possible duplicate of [How to change the color of the cursor in the textfield?](http://stackoverflow.com/questions/2190352/how-to-change-the-color-of-the-cursor-in-the-textfield) – jscs Mar 15 '12 at 19:18

6 Answers6

8

In IOS 7 you can simple set tintColor, it change color for all active elements in view and subviews, includes cursor color:

_textField.tintColor = [UIColor redColor];
2
[[textField textInputTraits] setValue:[UIColor redColor] forKey:@"insertionPointColor"];
KubajzT
  • 34
  • 1
  • 5
    but note that by above code you get your solution, but your app may be rejected while submit to app store for review." – Mohit Nigam Dec 22 '12 at 20:47
  • Thanks@MohitNigam i want to know that apart from this solution, what's the good way to change the textfield cursor color for iOS6? – Anand Gautam Jul 14 '14 at 06:29
1

Try this:

[[textField valueForKey:@"textInputTraits"] setValue:CUSTOM_COLOR forKey:@"insertionPointColor"];

Despite it seems to be undocumented, but it works. Frankly, you don't use any private methods here - only Key-Value Coding which is legal.

P.S. Yesterday my new app appeared at AppStore without any problems with this approach. And it is not the first case when I use KVC in changing some read-only properties (like navigatonBar) or private ivars.

malex
  • 9,374
  • 3
  • 53
  • 71
0

For iOS 10 SDK , only the indicator, and Objective-C (someday will be missed) my working solution is :

for (UIView *subView in self.sBar.subviews){
    for (UIView *ndLevelSubView in subView.subviews){

        if ([ndLevelSubView isKindOfClass:[UITextField class]])
        {
            UITextField * sbTextField = (UITextField *)ndLevelSubView;
            [[sbTextField valueForKey:@"textInputTraits"] setValue:[UIColor n2pMainPurpleColor] forKey:@"insertionPointColor"];
            break;
        }

    }

}
0

There is no documented way to change the pointer's color. Hovewer, there is one undocumented textField's property, namely textInputTraits, which is an UITextInputTraits instance.

You can try this code to get this working, but your app may be rejected in review process.

[[textField textInputTraits] setValue:[UIColor redColor] forKey:@"insertionPointColor"];

Taken from https://stackoverflow.com/a/4273440/736649

Community
  • 1
  • 1
akashivskyy
  • 40,844
  • 15
  • 103
  • 113
-1

Change the tint color, (iOS 7)

Change the tint color in the nib

or do it programmatically

myTextField.tintColor = [UIColor blackColor];

aToz
  • 2,429
  • 1
  • 22
  • 34