为开关创建自定义渲染(UISwitch https://developer.xamarin.com/api/type/MonoTouch.UIKit.UISwitch/在 iOS 中)并设置其色调颜色 https://developer.xamarin.com/api/property/MonoTouch.UIKit.UISwitch.OnTintColor/财产。
在PCL中:
public class CustomSwitch : Switch
{
}
In iOS :
[assembly: ExportRenderer(typeof(CustomSwitch), typeof(CustomSwitchRenderer))]
namespace xyz.iOS.CustomControlRenderers
{
public class CustomSwitchRenderer : SwitchRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<Switch> e)
{
base.OnElementChanged (e);
if (Control != null)
{
// do whatever you want to the UISwitch here!
Control.OnTintColor = UIColor.FromRGB (204, 153, 255);
}
}
}
}
由于您不需要对 Android 进行任何自定义,因此您无需在 Android 平台中创建自定义渲染。
您可以从以下位置获取与 Forms 实现对应的所有本机渲染的列表here https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/renderers/。
可以找到自定义渲染的示例here https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/entry/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)