因此,我在Visual Studio中进行编码,并在xaml文件中添加了一个选择器。一切都已设置好并且工作正常。我什至可以更改选择器本身的文本,标题,背景等颜色……
但是,当您单击选择器时,会弹出此框,其中包含要选择的项目...如何访问这些颜色/样式以进行更改?
我的整个应用看起来都是自定义的,但是那个小选择框看起来是默认的。(蓝色按钮为浅灰色背景和灰色文本)
我正在iOS模拟器上运行该应用程序。
请帮忙。谢谢
您需要一个自定义渲染器来更改项目和按钮样式。
这是一个例子:
[assembly:ExportRenderer(typeof(Picker), typeof(MyiOSPicker))]
namespace App493.iOS
{
public class MyiOSPicker : PickerRenderer, IUIPickerViewDelegate
{
IElementController ElementController => Element as IElementController;
public MyiOSPicker()
{
}
[Export("pickerView:viewForRow:forComponent:reusingView:")]
public UIView GetView(UIPickerView pickerView, nint row, nint component, UIView view)
{
UILabel label = new UILabel
{
//here you can set the style of item!!!
TextColor = UIColor.Red,
Text = Element.Items[(int)row].ToString(),
TextAlignment = UITextAlignment.Center,
};
return label;
}
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
if (Control != null)
{
UIPickerView pickerView = (UIPickerView)Control.InputView;
pickerView.WeakDelegate = this;
pickerView.BackgroundColor = UIColor.Yellow; //set the background color of pickerview
//To custom the done button
var toolBar = (UIToolbar)Control.InputAccessoryView;
var doneButton = toolBar.Items[1];
UITextAttributes att = new UITextAttributes
{
Font = UIFont.SystemFontOfSize(20.0f, UIFontWeight.Bold),
TextColor = UIColor.Green
};
doneButton.SetTitleTextAttributes(att, UIControlState.Normal);
}
}
}
}
结果如下:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句