c# - Xamarin 表单切换按钮在 IOS 上的默认颜色

标签 c# ios xamarin xamarin.forms

如何更改 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 平台中创建自定义渲染。

您可以从 here 获取 Forms 实现对应的所有原生渲染列表。 可以找到自定义渲染的示例 here

关于c# - Xamarin 表单切换按钮在 IOS 上的默认颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38993959/

相关文章:

xaml - 当内容不可见时隐藏列或行

c# - 在 C# 中实现全局常量的最佳方法是什么?

ios - 3D Peek and Pop 内存泄漏

Android 和 iOS HERE map 可以在 Polygon 上显示流量吗?

ios - 如何在 Charles Proxy 中查看 Web 套接字请求

android - 本地源图像绑定(bind)到 MvxImageView

xamarin - 如何将 TableView 滚动到顶部

c# - 将元数据与 Entity Framework 结合使用以使用数据注释进行验证

c# - 在 Windows 窗体中四舍五入选项卡标题

C# 使用 HTML Agility Pack 解析隐藏字段