简体   繁体   English

使用Userattributes更改UITextField的占位符文本颜色?

[英]Change UITextField's placeholder text color using Userattributes?

I want to change Place holder color from user attributes (interface builder) because i dont want to subclass my UITextfield etc... i searched on internet and found this "_placeholderLabel.textColor" Yes this works well Programmatically [self.tfEmail setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"]; 我想从用户属性(界面构建器)更改Place holder颜色,因为我不想继承我的UITextfield等...我在互联网上搜索并发现这个“_placeholderLabel.textColor”是的,这可以很好地编程[self.tfEmail setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"]; but i want to use it in user attributes in interface builder. 但我想在界面构建器中的用户属性中使用它。

Try removing '_', 尝试删除'_',

图片

Works for me. 适合我。

Without USING USER ATTRIBUTES 不使用用户属性

 self.txtField.attributedPlaceholder = PlaceHolderAttributedString(@"ABCDEF");

where PlaceHolderAttributedString is a macro defined as 其中PlaceHolderAttributedString是定义为的宏

 #define PlaceHolderAttributedString(placeHolderText) [[NSAttributedString alloc] initWithString:placeHolderText attributes:@{NSForegroundColorAttributeName:ColorTextFieldPlaceHolder}]

USING USER ATTRIBUTES 使用用户属性

 placeholderLabel.textColor 

在swift中:

    one_textfield.setValue(UIColor.redColor(), forKeyPath: "_placeholderLabel.textColor")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM