Change UITextField's placeholder text color using Userattributes?

你离开我真会死。 提交于 2019-12-21 04:12:49

问题


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"]; but i want to use it in user attributes in interface builder.


回答1:


Try removing '_',

Works for me.




回答2:


Without USING USER ATTRIBUTES

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

where PlaceHolderAttributedString is a macro defined as

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

USING USER ATTRIBUTES

 placeholderLabel.textColor 



回答3:


in swift:

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


来源:https://stackoverflow.com/questions/21156009/change-uitextfields-placeholder-text-color-using-userattributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!