protected override void OnAttached() { formsEditor = Element as EditorWithPlaceholder; nativeTextField = Control as EditText; try { placeholderText = new TextView(Forms.Context) { Text = formsEditor.Placeholder, }; placeholderText.SetBackgroundColor(Android.Graphics.Color.Transparent); placeholderText.SetTextColor(formsEditor.PlaceholderTextColor.ToAndroid()); placeholderText.SetLines(1); backgroundColor = Android.Graphics.Color.White; Control.SetBackgroundColor(backgroundColor); if (string.IsNullOrEmpty(formsEditor.Text)) { placeholderText.Alpha = 1; } else { placeholderText.Alpha = 0; } nativeTextField.Add(placeholderText); } catch (Exception ex) { Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message); } }
protected override void OnAttached() { formsEditor = Element as EditorWithPlaceholder; nativeTextField = Control as UITextView; placeholderText = new UILabel { LineBreakMode = UILineBreakMode.WordWrap, Lines = 1, BackgroundColor = UIColor.Clear, TextColor = formsEditor.PlaceholderTextColor.ToUIColor(), Text = formsEditor.Placeholder }; if (string.IsNullOrEmpty(formsEditor.Text)) { placeholderText.Alpha = 1; } else { placeholderText.Alpha = 0; } nativeTextField.AddSubview(placeholderText); }
private void CreatePlaceholderLabel(EditorWithPlaceholder element, UITextView parent) { placeholderLabel = new UILabel { Text = element.Placeholder, TextColor = element.PlaceholderColor.ToUIColor(), BackgroundColor = UIColor.Clear, TextAlignment = UITextAlignment.Natural }; placeholderLabel.SizeToFit(); parent.AddSubview(placeholderLabel); parent.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints(); parent.AddConstraints(placeholderLabel.AtLeftOf(parent, 7), placeholderLabel.WithSameCenterY(parent)); parent.LayoutIfNeeded(); placeholderLabel.Hidden = parent.HasText; }