Exemplo n.º 1
0
        public TextFieldWithPopup(UITextField textField, UIViewController controller)
        {
            _controller = controller;
            _textField  = textField;
            _button     = new UIButton(new CGRect(0, 0, _textField.Bounds.Size.Width, _textField.Bounds.Size.Height));
            _button.AutoresizingMask = UIViewAutoresizing.All;
            _button.TouchUpInside   += (sender, e) => {
                var popPresenter = _customAlertController.AlertController.PopoverPresentationController;
                if (popPresenter != null)
                {
                    popPresenter.SourceView = textField;
                    popPresenter.SourceRect = textField.Bounds;
                }
                _controller.PresentViewController(_customAlertController.AlertController, true, null);
            };
            _textField.AddSubview(_button);

            CustomizeTextField();

            _button.TranslatesAutoresizingMaskIntoConstraints = false;
            _button.TopAnchor.ConstraintEqualTo(_textField.TopAnchor, 0).Active           = true;
            _button.BottomAnchor.ConstraintEqualTo(_textField.BottomAnchor, 0).Active     = true;
            _button.LeadingAnchor.ConstraintEqualTo(_textField.LeadingAnchor, 0).Active   = true;
            _button.TrailingAnchor.ConstraintEqualTo(_textField.TrailingAnchor, 0).Active = true;
        }
Exemplo n.º 2
0
        public static void AddBottomBorder(this UITextField textField, UIColor color, float height = 1f)
        {
            var border = textField.Subviews?.FirstOrDefault(view => view.AccessibilityIdentifier == "bottom_border");

            border?.RemoveFromSuperview();

            textField.BorderStyle     = UITextBorderStyle.None;
            textField.BackgroundColor = UIColor.Clear;

            var borderLine = new UIView(new CGRect(0, textField.Frame.Height - height, textField.Frame.Width,
                                                   height))
            {
                BackgroundColor = color, AccessibilityIdentifier = "bottom_border"
            };

            textField.AddSubview(borderLine);
        }