如何更改 IOS 上的切换按钮默认颜色(绿色)?
最佳答案
为开关创建自定义渲染(iOS 中的 UISwitch)并设置其 OnTintColor属性(property)。
在 PCL 中:
public class CustomSwitch : Switch
{
}
在 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 平台中创建自定义渲染。
关于c# - Xamarin 表单切换按钮在 IOS 上的默认颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38993959/