iOS 8文本字段着色颜色
在iOS 7中,更改uitextfield的“tint color”属性将更改该文本字段的光标颜色。在iOS 8中,即使我更改了全局情节提要颜色,也不会发生这种情况(objective-c在iOS 7中仍然有效)。如何解决此问题?我刚刚尝试复制您的问题,但在iOS7.1和iOS8上,文本字段的tintColor属性都可以完美地工作 这行代码更改文本字段的光标颜色。尝试此操作,而不是更改故事板中的着色颜色iOS 8文本字段着色颜色,ios,objective-c,xcode,ios8,tint,Ios,Objective C,Xcode,Ios8,Tint,在iOS 7中,更改uitextfield的“tint color”属性将更改该文本字段的光标颜色。在iOS 8中,即使我更改了全局情节提要颜色,也不会发生这种情况(objective-c在iOS 7中仍然有效)。如何解决此问题?我刚刚尝试复制您的问题,但在iOS7.1和iOS8上,文本字段的tintColor属性都可以完美地工作 这行代码更改文本字段的光标颜色。尝试此操作,而不是更改故事板中的着色颜色 textField.tintColor = [UIColor colorWithRed:98
textField.tintColor = [UIColor colorWithRed:98.0/255.0f green:98.0/255.0f blue:98.0/255.0f alpha:1.0];
希望有帮助 尝试以下操作:
[[self.textField setTintColor:[UIColor blueColor]];
[self.textField setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];
是否希望在整个视图上实际放置着色颜色过滤器,而不仅仅是更改光标颜色?
别再看了.tint
是一个蹩脚的名称,因为它绝不意味着它会调整光标颜色。当然,人们在谷歌上搜索.tint
属性可能会试图找到一种方法,在UIView、UITextView的整个帧/区域应用颜色过滤器
以下是我为您提供的解决方案:
我为此制作了宏:
#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];\
}
要使用,只需调用:
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];
去除色调时,只需调用:
removeTint(yourView);
这应该被接受。我还是不明白,为什么它不能通过故事板工作。谢谢。无
self.tinadjustmentmode=ui查看tinadjustmentmodenormal代码>设置颜色将不起作用。