我使用一个特定的选择器设置来模仿Xamarin.iOS中下拉列表的操作。代码为:
public void ConfigureSelectPicker(UITextField pickerTextField, List<string> theData)
{
PickerViewModel MyModel = new PickerViewModel();
MyModel._pickerSource = theData;
var picker = new UIPickerView
{
Model = MyModel,
ShowSelectionIndicator = true,
TintColor = UIColor.Blue
};
var screenWidth = UIScreen.MainScreen.Bounds.Width;
var pickerToolBar = new UIToolbar(new RectangleF(0, 0, (float)screenWidth, 44)) { BarStyle = UIBarStyle.Default, Translucent = true };
var flexibleSpaceButton = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) => pickerTextField.ResignFirstResponder());
doneButton.Clicked += (object sender, EventArgs e) =>
{
pickerTextField.Text = MyModel.SelectedItem;
};
pickerToolBar.SetItems(new[] { flexibleSpaceButton, doneButton }, false);
pickerTextField.InputView = picker;
pickerTextField.InputAccessoryView = pickerToolBar;
}
字符串theData
列表包含在选择器中被截断的字符串。有没有一种方法可以改变字体大小,使他们适合也文本颜色?
1条答案
按热度按时间qlvxas9a1#
您可以覆盖UIPickerViewModel中的GetView方法。
字符串
有关更多信息,您可以参考Picker control in Xamarin.iOS和示例代码:PickerControl。