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

我想从用户属性(接口生成器)更改占位符的颜色,因为我不想要inheritance我的UITextfield等…我在互联网上search,发现这个“_placeholderLabel.textColor”是这个效果很好编程[self.tfEmail setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"]; 但我想在界面生成器的用户属性中使用它。

尝试删除“_”,

图片

为我工作。

没有使用用户属性

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

PlaceHolderAttributedString是一个定义为的macros

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

使用用户属性

  placeholderLabel.textColor 

在迅速:

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