Xamarin iOS隐藏占位符点击



我有一个Xamarin iOS应用程序,它有文本字段,所以我想让我的文本字段隐藏他们的占位符点击不只是当我开始输入字母,这是可能的吗?

类似如下:

  string _placeHolderText = "Some Test Placeholder...";
  public override void ViewWillAppear (bool animated)
  {
     base.ViewWillAppear (animated);
     var textView1 = new UITextField (new CGRect (0, 0, UIScreen.MainScreen.Bounds.Width, 100)) {
        Placeholder = _placeHolderText,
        BorderStyle = UITextBorderStyle.Line
     };
     textView1.EditingDidBegin += (object sender, EventArgs e) =>
     {
        textView1.Placeholder = string.Empty;
     };
     textView1.EditingDidEnd += (object sender, EventArgs e) =>
     {
        textView1.Placeholder = _placeHolderText;
     };
     var textView2 = new UITextField (new CGRect (0, textView1.Frame.Bottom, UIScreen.MainScreen.Bounds.Width, 100)) {
        Placeholder = _placeHolderText,
        BorderStyle = UITextBorderStyle.Line
     };
     this.View.AddSubviews (textView1, textView2);
  }

这是可能的,您可以在文本字段开始编辑时将占位符文本设置为空字符串,并在编辑结束且仍为空时将其重置为先前的值

最新更新