Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin iOS在单击时隐藏占位符_C#_Xamarin_Xamarin.ios_Placeholder - Fatal编程技术网

C# Xamarin iOS在单击时隐藏占位符

C# Xamarin iOS在单击时隐藏占位符,c#,xamarin,xamarin.ios,placeholder,C#,Xamarin,Xamarin.ios,Placeholder,我有一个Xamarin iOS应用程序,它有文本字段,所以我想让我的文本字段在单击时隐藏其占位符,而不仅仅是在我开始输入字母时,有可能吗?有可能,当文本字段开始编辑时,您可以将占位符文本设置为空字符串,如果结束编辑且仍然为空,则将其重置为上一个值。您可以在文本字段开始编辑时将占位符文本设置为空字符串,如果结束编辑且仍然为空,则将其重置为上一个值。如下所示: string _placeHolderText = "Some Test Placeholder..."; public over

我有一个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);
  }
如下所示:

  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);
  }