Exemplo n.º 1
0
        protected override void OnAttached()
        {
            _textView         = Control as UITextView;
            _placeholderLabel = new UILabel();

            _placeholderLabel.LineBreakMode   = UILineBreakMode.WordWrap;
            _placeholderLabel.Lines           = 0;
            _placeholderLabel.Font            = _textView.Font;
            _placeholderLabel.BackgroundColor = UIColor.Clear;
            _placeholderLabel.Alpha           = 0;

            UpdateText();
            UpdateColor();

            _textView.AddSubview(_placeholderLabel);

            _placeholderLabel.TranslatesAutoresizingMaskIntoConstraints = false;

            _placeholderLabel.TopAnchor.ConstraintEqualTo(_textView.TopAnchor, 8).Active         = true;
            _placeholderLabel.LeftAnchor.ConstraintEqualTo(_textView.LeftAnchor, 4).Active       = true;
            _placeholderLabel.RightAnchor.ConstraintEqualTo(_textView.RightAnchor, 4).Active     = true;
            _placeholderLabel.WidthAnchor.ConstraintEqualTo(_textView.WidthAnchor, 1, -8).Active = true;

            _textView.SendSubviewToBack(_placeholderLabel);

            if (_textView.Text.Length == 0 && _placeholderLabel.Text.Length > 0)
            {
                _placeholderLabel.Alpha = 1;
            }

            _textView.Changed += _textView_Changed;
        }