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?
Asked
Active
Viewed 5,778 times
3 Answers
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
-
4This should be the accepted. I still didn't get it, why it doesn't work via storyboard. – appsunited Nov 27 '14 at 11:18
8
try the following:
[[self.textField setTintColor:[UIColor blueColor]];
[self.textField setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];
-
2Thank you. Without `self.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;` setting tintColor won't work. – Kamil Powałowski Jul 30 '15 at 07:46
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