/// <summary> /// Presents a new color picker. /// </summary> /// <param name="parent">The parent <see cref="UIViewController"/>.</param> /// <param name="title">The picker title.</param> /// <param name="initialColor">The initial selected color.</param> /// <param name="done">The method invoked when the picker closes.</param> /// <param name="colorPicked">The method invoked as colors are picked.</param> public static void Present(UIViewController parent, string title, UIColor initialColor, Action <UIColor> done, Action <UIColor> colorPicked) { if (parent == null) { throw new ArgumentNullException("parent"); } var picker = new ColorPickerViewController { Title = title, SelectedColor = initialColor }; picker.ColorPicked += (_, args) => { if (colorPicked != null) { colorPicked(args.SelectedColor); } }; var pickerNav = new UINavigationController(picker); pickerNav.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; pickerNav.NavigationBar.Translucent = false; var doneBtn = new UIBarButtonItem(UIBarButtonSystemItem.Done); picker.NavigationItem.RightBarButtonItem = doneBtn; doneBtn.Clicked += delegate { if (done != null) { done(picker.SelectedColor); } // hide the picker parent.DismissViewController(true, null); }; // show the picker parent.PresentViewController(pickerNav, true, null); }
/// <summary> /// Presents a new color picker. /// </summary> /// <param name="parent">The parent <see cref="UIViewController"/>.</param> /// <param name="title">The picker title.</param> /// <param name="initialColor">The initial selected color.</param> /// <param name="done">The method invoked when the picker closes.</param> /// <param name="colorPicked">The method invoked as colors are picked.</param> public static void Present(UIViewController parent, string title, UIColor initialColor, Action<UIColor> done, Action<UIColor> colorPicked) { if (parent == null) { throw new ArgumentNullException("parent"); } var picker = new ColorPickerViewController { Title = title, SelectedColor = initialColor }; picker.ColorPicked += (_, args) => { if (colorPicked != null) { colorPicked(args.SelectedColor); } }; var pickerNav = new UINavigationController(picker); pickerNav.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; pickerNav.NavigationBar.Translucent = false; var doneBtn = new UIBarButtonItem(UIBarButtonSystemItem.Done); picker.NavigationItem.RightBarButtonItem = doneBtn; doneBtn.Clicked += delegate { if (done != null) { done(picker.SelectedColor); } // hide the picker parent.DismissViewController(true, null); }; // show the picker parent.PresentViewController(pickerNav, true, null); }
private void SetupColorPicker() { this.colorPicker = new ColorPickerViewController(); this.colorPicker.Title = "Pick a color!"; this.colorPickerNavigationController = new UINavigationController(this.colorPicker); this.colorPickerNavigationController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; this.colorPicker.NavigationItem.RightBarButtonItem = new UIBarButtonItem (UIBarButtonSystemItem.Done); this.colorPicker.NavigationItem.RightBarButtonItem.Clicked += this.OnColorPickerDoneButtonClicked; }
void pickAColorBtn_HandleTouchUpInside(object sender, EventArgs e) { picker = new ColorPickerViewController(); picker.ColorPicked += HandleColorPicked; picker.Title = "Pick a color!"; UINavigationController pickerNav = new UINavigationController(picker); pickerNav.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; doneBtn = new UIBarButtonItem(UIBarButtonSystemItem.Done); picker.NavigationItem.RightBarButtonItem = doneBtn; doneBtn.Clicked += doneBtn_HandleClicked; nav.PresentModalViewController(pickerNav,true); }