Пример #1
0
        void CreatePicker()
        {
            _entry                 = new NoCaretField();
            _entry.BorderStyle     = UITextBorderStyle.None;
            _entry.BackgroundColor = UIColor.Clear;
            _view.AddSubview(_entry);

            //_view.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
            _entry.TranslatesAutoresizingMaskIntoConstraints = false;

            _constraint = CreateConstraint(_view, _entry);

            _view.UserInteractionEnabled = true;
            _view.AddConstraints(_constraint);
            _view.SendSubviewToBack(_entry);

            _picker = new UIPickerView();

            var width   = UIScreen.MainScreen.Bounds.Width;
            var toolbar = new UIToolbar(new CGRect(0, 0, (float)width, 44))
            {
                BarStyle = UIBarStyle.Default, Translucent = true
            };

            var cancelButton = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (o, e) => {
                _entry.ResignFirstResponder();
                Select(_model.PreSelectedItem);
            });

            _title = new UILabel();
            var labelButton = new UIBarButtonItem(_title);

            var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);

            var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => {
                var s = (NumberPickerSource)_picker.Model;
                UpdatePickerFromModel(s);
                _entry.ResignFirstResponder();
                _command?.Execute(s.SelectedItem);
            });

            toolbar.SetItems(new[] { cancelButton, spacer, labelButton, spacer, doneButton }, false);

            _entry.InputView          = _picker;
            _entry.InputAccessoryView = toolbar;

            _model        = new NumberPickerSource();
            _picker.Model = _model;
        }
Пример #2
0
 void UpdatePickerFromModel(NumberPickerSource s)
 {
     _model.PreSelectedItem = s.SelectedItem;
     AddNumberPicker.SetNumber(Element, s.SelectedItem);
 }