我有一个Xamarin iOS应用程序和一些文本字段,每个都有一个占位符,当它被选中时会被删除,我希望它在输入为空或空时恢复,我该如何获取它?
I tried that:
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
string placeholderAux = txt.Placeholder;
txt.EditingDidBegin += (object sender, EventArgs e) =>{
if (string.IsNullOrWhiteSpace(txt.Text))
{
txt.Placeholder = placeholderAux;
}
};
}
但它不起作用
答案 0 :(得分:1)
textField.EditingDidBegin += (object sender, EventArgs e) =>
{
(sender as UITextField).Placeholder = "";
};
textField.EditingDidEnd += (object sender, EventArgs e) =>
{
var uITextField = sender as UITextField;
if (string.IsNullOrEmpty(uITextField.Text))
{
uITextField.Placeholder = "StackOverflow";
}
};
答案 1 :(得分:0)
尝试一下:
textField.AttributedPlaceholder = new NSAttributedString("place holder", foregroundColor: UIColor.FromRGB(204 ,204,204));