Exemple #1
0
        void CreatePicker()
        {
            _entry                 = new NoCaretField();
            _entry.BorderStyle     = UITextBorderStyle.None;
            _entry.BackgroundColor = UIColor.Clear;
            _view.AddSubview(_entry);

            _entry.TranslatesAutoresizingMaskIntoConstraints = false;

            _entry.TopAnchor.ConstraintEqualTo(_view.TopAnchor).Active       = true;
            _entry.LeftAnchor.ConstraintEqualTo(_view.LeftAnchor).Active     = true;
            _entry.BottomAnchor.ConstraintEqualTo(_view.BottomAnchor).Active = true;
            _entry.RightAnchor.ConstraintEqualTo(_view.RightAnchor).Active   = true;
            _entry.WidthAnchor.ConstraintEqualTo(_view.WidthAnchor).Active   = true;
            _entry.HeightAnchor.ConstraintEqualTo(_view.HeightAnchor).Active = true;

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

            _picker = new UIDatePicker {
                Mode = UIDatePickerMode.Date, TimeZone = new Foundation.NSTimeZone("UTC")
            };
            var todayText = AddDatePicker.GetTodayText(Element);

            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();
                _picker.Date = _preSelectedDate;
            });

            var spacer     = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
            var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => {
                _entry.ResignFirstResponder();
                DoneDate();
                _command?.Execute(_picker.Date.ToDateTime().Date);
            });

            if (!string.IsNullOrEmpty(todayText))
            {
                var labelButton = new UIBarButtonItem(todayText, UIBarButtonItemStyle.Plain, (sender, e) => {
                    SetToday();
                });
                var fixspacer = new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace)
                {
                    Width = 20
                };
                toolbar.SetItems(new[] { cancelButton, spacer, labelButton, fixspacer, doneButton }, false);
            }
            else
            {
                toolbar.SetItems(new[] { cancelButton, spacer, doneButton }, false);
            }

            _entry.InputView          = _picker;
            _entry.InputAccessoryView = toolbar;
        }
Exemple #2
0
        void CreatePicker()
        {
            _entry                 = new NoCaretField();
            _entry.BorderStyle     = UITextBorderStyle.None;
            _entry.BackgroundColor = UIColor.Clear;
            _view.AddSubview(_entry);

            _entry.TranslatesAutoresizingMaskIntoConstraints = false;

            _entry.TopAnchor.ConstraintEqualTo(_view.TopAnchor).Active       = true;
            _entry.LeftAnchor.ConstraintEqualTo(_view.LeftAnchor).Active     = true;
            _entry.BottomAnchor.ConstraintEqualTo(_view.BottomAnchor).Active = true;
            _entry.RightAnchor.ConstraintEqualTo(_view.RightAnchor).Active   = true;
            _entry.WidthAnchor.ConstraintEqualTo(_view.WidthAnchor).Active   = true;
            _entry.HeightAnchor.ConstraintEqualTo(_view.HeightAnchor).Active = true;

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

            _picker = new UIDatePicker {
                Mode = UIDatePickerMode.Time, TimeZone = new Foundation.NSTimeZone("UTC")
            };
            if (UIDevice.CurrentDevice.CheckSystemVersion(14, 0))
            {
                _picker.PreferredDatePickerStyle = UIDatePickerStyle.Wheels;
            }

            _title = new UILabel();

            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();
                _picker.Date = _preSelectedDate;
            });

            var labelButton = new UIBarButtonItem(_title);
            var spacer      = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
            var doneButton  = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => {
                _entry.ResignFirstResponder();
                DoneTime();
                _command?.Execute(_picker.Date.ToDateTime() - new DateTime(1, 1, 1));
            });

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

            _entry.InputView          = _picker;
            _entry.InputAccessoryView = toolbar;
        }
Exemple #3
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;
        }