8

In iOS 7, changing the 'tint color' attribute of a uitextfield would change the cursor color of that text field. In iOS 8, even when I change the global storyboard tint color, this does not occur (objective-c, still works in iOS 7). How do I fix this?

Jack Solomon
  • 880
  • 1
  • 8
  • 19

3 Answers3

12

I just tried to replicate your problem but both on iOS7.1 and iOS8 the tintColor attribute of a textfield works perfectly.

This line of code change the cursor color of the textField. Try this instead of changing the tint color in Storyboard

textField.tintColor = [UIColor colorWithRed:98.0/255.0f green:98.0/255.0f blue:98.0/255.0f alpha:1.0];

Hope it helps!

Niccolò Passolunghi
  • 5,966
  • 2
  • 25
  • 34
8

try the following:

[[self.textField setTintColor:[UIColor blueColor]];

[self.textField setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];
DJanssens
  • 17,849
  • 7
  • 27
  • 42
George
  • 202
  • 2
  • 8
0

Looking to actually put a tinted color filter on the whole view, not just change cursor color?

Look no further. .tint is a lame name because it in no way implies that it adjusts the cursor color. Naturally, people googling about the .tint property are likely trying to find a way to apply a color filter across the whole frame/region of their UIView, UITextView, whatever.

Here is my solution for you:

I made macros for this purpose:

#define removeTint(view) \
if ([((NSNumber *)[view.layer valueForKey:@"__hasTint"]) boolValue]) {\
for (CALayer *layer in [view.layer sublayers]) {\
if ([((NSNumber *)[layer valueForKey:@"__isTintLayer"]) boolValue]) {\
[layer removeFromSuperlayer];\
break;\
}\
}\
}

#define setTint(view, tintColor) \
{\
if ([((NSNumber *)[view.layer valueForKey:@"__hasTint"]) boolValue]) {\
removeTint(view);\
}\
[view.layer setValue:@(YES) forKey:@"__hasTint"];\
CALayer *tintLayer = [CALayer new];\
tintLayer.frame = view.bounds;\
tintLayer.backgroundColor = [tintColor CGColor];\
[tintLayer setValue:@(YES) forKey:@"__isTintLayer"];\
[view.layer addSublayer:tintLayer];\
}

To use, simply just call:

setTint(yourView, yourUIColor);
//Note: include opacity of tint in your UIColor using the alpha channel (RGBA), e.g. [UIColor colorWithRed:0.5f green:0.0 blue:0.0 alpha:0.25f];

When removing the tint simply call:

removeTint(yourView);
Community
  • 1
  • 1
Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195