xcode 替换 UITextField 占位符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16032776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replace UITextField Placeholder
提问by Nagasaki
I have a 'IBOutlet UITextField* textField' connect with a UITextField in a .xib file. I use this element as a combobox in a viewcontroller class which is connect to a VC in the storyboard. My question is how can i modify the placeholder text? I already try the 3 following methods, but nothing work!!
我有一个 'IBOutlet UITextField* textField' 与 .xib 文件中的 UITextField 连接。我将此元素用作视图控制器类中的组合框,该类连接到故事板中的 VC。我的问题是如何修改占位符文本?我已经尝试了以下 3 种方法,但没有任何效果!!
-(void) setPlaceholder:(NSString *)label
{
textField.placeholder = label;
[textField setPlaceholder:label];
[textField cell ]setPlaceholderString:label];
}
thx for your answers
谢谢你的回答
采纳答案by Zehn
put it in the viewdidload method of your viewcontroller method because the placeholder field wasn't initialize when i called my setPlaceholder method
把它放在你的 viewcontroller 方法的 viewdidload 方法中,因为当我调用我的 setPlaceholder 方法时,占位符字段没有初始化
回答by Zehn
As long as you're textField has been synthesised, you should be able to use:
textField.placeholder = label
只要你的 textField 已经合成,你应该可以使用:
textField.placeholder = label
回答by Ishank
textField.placeholder = @"placeholder"
shall work, check if label
and textField
actually point to respective objects.
textField.placeholder = @"placeholder"
应该工作,检查是否label
并textField
实际指向相应的对象。