2014-01-16 120 views
10

我想更改佔位符顏色從用戶屬性(接口生成器),因爲我不想要繼承我的UITextfield等...我在互聯網上搜索,發現這個「_placeholderLabel.textColor」是的這很好用編程方式[self.tfEmail setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];但我想在界面構建器的用戶屬性中使用它。使用Userattributes更改UITextField的佔位符文本顏色?

回答

22

嘗試去掉 '_',

Image

爲我工作。

+1

大聲笑我從來沒有人像這樣的佔位符在界面生成器!啊哈真棒,我想知道還有什麼可以使用相同的方法 – Pavan

+1

簡單真棒.. ..好朋友。 –

+3

您可以更改字體,您可以更改存在的任何屬性。不需要以編程方式進行。 – Xeieshan

4

而不使用用戶屬性

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

其中PlaceHolderAttributedString在宏定義爲

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

USING用戶屬性

placeholderLabel.textColor 
0

在迅速:

one_textfield.setValue(UIColor.redColor(), forKeyPath: "_placeholderLabel.textColor") 
相關問題