Skip to content

Instantly share code, notes, and snippets.

@nodoid
Created February 26, 2015 15:22
Show Gist options
  • Save nodoid/a2dc344e74be163d4d5f to your computer and use it in GitHub Desktop.
Save nodoid/a2dc344e74be163d4d5f to your computer and use it in GitHub Desktop.
UIPickerViews
// place this in your controller
// View is the view the control sits in
// txtSelect is the name of the textbox the spinner "sits" in - as soon as you select
// the textbox, the UIPickerView fires up
// information is a List<string>
txtSelect.EditingDidBegin += delegate
{
txtSelect.InputView = PickerUI.CreateDropList(View, new UIPickerView(), txtSelect, information);
};
// PickerUI.cs
public static class PickerUI
{
public static UIView CreateDropList(UIView view, UIPickerView picker, UITextField txtField, List<string> param)
{
var choiceModel = new PickerModel((IList<string>)param);
string imp = param[0];
picker = new UIPickerView(new CGRect(0, 44, view.Bounds.Width, 216))
{
Model = choiceModel,
BackgroundColor = UIColor.LightGray,
ShowSelectionIndicator = true,
Hidden = false,
AutosizesSubviews = true,
};
var toolHigh = new UIToolbar
{
BarStyle = UIBarStyle.Black,
Translucent = true,
UserInteractionEnabled = true
};
toolHigh.SizeToFit();
var doneHigh = new UIBarButtonItem(StringUtils.GetString("Common.Done"), UIBarButtonItemStyle.Done,
(ss, ea) =>
{
picker.ResignFirstResponder();
txtField.Text = imp;
txtField.ResignFirstResponder();
});
toolHigh.SetItems(new UIBarButtonItem[] { doneHigh }, true);
var pickView = new UIView(new CGRect(0, 0, view.Bounds.Width, 260));
pickView.AddSubviews(new UIView[]{ picker, toolHigh });
choiceModel.PickerChanged += (object sender, PickerChangedEventArgs ea) =>
{
imp = ea.SelectedValue;
};
return pickView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment