【问题标题】:Xamarin iOS hide placeholder on clickXamarin iOS 在点击时隐藏占位符
【发布时间】:2015-12-02 15:35:56
【问题描述】:

我有一个 Xamarin iOS 应用程序,它有文本字段,所以我希望我的文本字段在点击时隐藏它们的占位符,而不仅仅是在我开始输入字母时,这可能吗?

【问题讨论】:

    标签: c# xamarin xamarin.ios placeholder


    【解决方案1】:

    有可能,您可以在文本字段开始编辑时将占位符文本设置为空字符串,如果结束编辑仍为空,则将其重置为之前的值。

    【讨论】:

      【解决方案2】:

      如下所示:

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

      【讨论】:

        猜你喜欢
        • 2013-02-07
        • 1970-01-01
        • 1970-01-01
        • 2012-07-13
        • 2017-07-28
        • 2014-02-24
        • 2016-09-13
        • 2021-11-10
        • 2021-08-25
        相关资源
        最近更新 更多