Exemplo n.º 1
0
 protected void OnPickerItemSelected(UIPickerView picker, nint row, nint component, IDPair selectedItem)
 {
     CoreUtility.ExecuteMethod("OnPickerItemSelected", delegate()
     {
         UIView selectedView          = picker.ViewFor(row, component);
         selectedView.BackgroundColor = _colorOfSelectedItem;
     });
 }
Exemplo n.º 2
0
            public override void Selected(UIPickerView pickerView, int row, int component)
            {
                var n = pickerView.RowsInComponent(0);

                var cpv = (CheckedPickerView)pickerView;

                cpv.SelectedItem = cpv.Items[row];

                for (var i = 0; i < n; i++)
                {
                    var label = (PickerLabel)pickerView.ViewFor(i, 0);
                    label.IsSelected = cpv.selectedItem == label.Text;
                }
            }
			public override void Selected (UIPickerView pickerView, int row, int component)
			{
				var n = pickerView.RowsInComponent (0);

				var cpv = (CheckedPickerView)pickerView;

				cpv.SelectedItem = cpv.Items[row];
				
				for (var i = 0; i < n; i++) { 
					var label = (PickerLabel)pickerView.ViewFor (i, 0);
					label.IsSelected = cpv.selectedItem == label.Text;
				}
			}
Exemplo n.º 4
0
        public CustomPicker CreateCustomPicker()
        {
            return(CoreUtility.ExecuteFunction <CustomPicker> ("CreateCustomPicker", delegate()
            {
                if (_superView != null)
                {
                    //create picker view
                    UIPickerView pickerView = new UIPickerView()
                    {
                        ShowSelectionIndicator = true,
                        Hidden = false,
                        Frame = new CGRect(0, (_superView.Frame.Height - 216f), _superView.Frame.Width, 216f),
                        Opaque = true,
                        BackgroundColor = "#D1D5DB".ConvertHexToColor()
                    };

                    _source = new CustomPickerViewModel()
                              .For(_data)
                              .WhenSelected(this.OnPickerItemSelected);

                    pickerView.Model = _source;

                    UIView selectedItem = pickerView.ViewFor(pickerView.SelectedRowInComponent(0), 0);
                    if (selectedItem != null)
                    {
                        selectedItem.BackgroundColor = _colorOfSelectedItem;
                    }

                    _pickerView = pickerView;

                    //create grey container for done button
                    UIView vwBtnContainer = new UIView(new CGRect(0f, (_superView.Bounds.Height - 216f) - 40f, _superView.Bounds.Width, 40f));
                    vwBtnContainer.BackgroundColor = UIColor.DarkGray;
                    _vwBtnContainer = vwBtnContainer;


                    //create Done button
                    UIButton btnDone = new UIButton(UIButtonType.Custom)
                    {
                        Frame = new CGRect(_superView.Frame.Width - 60f, 5f, 50f, 30f),
                        Hidden = false
                    };
                    btnDone.Font = UIFont.BoldSystemFontOfSize(14f);
                    btnDone.BackgroundColor = UIColor.Clear;
                    btnDone.SetTitleColor(UIColor.White, UIControlState.Normal);
                    btnDone.SetTitle(_titleForDoneButton, UIControlState.Normal);
                    btnDone.TouchDown += (sender, e) =>
                    {
                        CoreUtility.ExecuteMethod("TouchDown", delegate()
                        {
                            if (this._onDoneClicked != null)
                            {
                                nint selectedRow = pickerView.SelectedRowInComponent(0);
                                this._onDoneClicked(_data[selectedRow]);
                            }
                            this.RemoveFromSuperview();
                        });
                    };
                    vwBtnContainer.Add(btnDone);

                    if (_triggerSource != null)
                    {
                        if (_triggerSource is UITextField)
                        {
                            (_triggerSource as UITextField).ShouldBeginEditing = ShowPickerFromTextField;
                        }
                        else
                        {
                            UITapGestureRecognizer tapGesture = new UITapGestureRecognizer(this.ShowPicker);
                            _triggerSource.AddGestureRecognizer(tapGesture);
                        }
                    }

                    this.AddSubview(_pickerView);
                    this.AddSubview(_vwBtnContainer);

                    if (!string.IsNullOrEmpty(_initialValue))
                    {
                        if (_data != null)
                        {
                            for (int i = 0; i < _data.Length; i++)
                            {
                                if (_data[i].id == _initialValue)
                                {
                                    _pickerView.Select(i, 0, false);
                                    break;
                                }
                            }
                        }
                    }
                }
                return this;
            }));
        }