Xamarin在IOS上设置切换按钮默认颜色 [英] Xamarin forms toggle button default color on IOS

查看:111
本文介绍了Xamarin在IOS上设置切换按钮默认颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改切换按钮的默认颜色,该颜色在IOS上为绿色?

How could I change the toggle button default color which is green on IOS?

推荐答案

为开关创建自定义渲染器( UISwitch )并设置其

Create a custom Render for the switch (UISwitch in iOS) and set its 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平台中创建自定义渲染.

Since you don't need any customizations for android you need not create a custom render in the android platform.

您可以从此处找到自定义渲染的示例.

You can get the list of all the native renders corresponding to Forms implementation from here. An example of custom render can be found here.

这篇关于Xamarin在IOS上设置切换按钮默认颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆