xamarin - 有没有办法使用渲染器更改 Xamarin 中 iOS 开关的轮廓颜色?
问题描述
我正在使用此类和渲染器,它允许我更改开关的颜色:
public class ExtSwitch : Switch
{
public static readonly BindableProperty SwitchOnColorProperty = BindableProperty.Create(nameof(SwitchOnColor), typeof(Color), typeof(ExtSwitch), Color.Default);
public static readonly BindableProperty SwitchOffColorProperty = BindableProperty.Create(nameof(SwitchOffColor), typeof(Color), typeof(ExtSwitch), Color.Default);
public static readonly BindableProperty SwitchThumbColorProperty = BindableProperty.Create(nameof(SwitchThumbColor), typeof(Color), typeof(ExtSwitch), Color.Default);
public Color SwitchOffColor { get => (Color)GetValue(SwitchOffColorProperty); set => SetValue(SwitchOffColorProperty, value); }
public Color SwitchOnColor { get => (Color)GetValue(SwitchOnColorProperty); set => SetValue(SwitchOnColorProperty, value); }
public Color SwitchThumbColor { get => (Color)GetValue(SwitchThumbColorProperty); set => SetValue(SwitchThumbColorProperty, value); }
}
和
class ExtSwitchRenderer : SwitchRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
{
base.OnElementChanged(e);
if (e.OldElement != null || e.NewElement == null) return;
ExtSwitch s = Element as ExtSwitch;
//this.Control.ThumbTintColor = s.SwitchThumbColor.ToUIColor();
this.Control.OnTintColor = s.SwitchOnColor.ToUIColor();
}
}
这会更改颜色,但不会更改开关的轮廓边框。在此图像中,它显示为白色:
有没有办法可以在iOS中将白色边框更改为另一种颜色?
解决方案
你应该改变 TintColor
this.Control.TintColor = s.SwitchOnColor.ToUIColor();
推荐阅读
- python - 发送 Facebook 消息
- react-native - 为嵌套视图禁用 TouchableOpacity
- go - Go Scanner 仍然返回
- python - 如何在jupyter中有条件地格式化熊猫行组
- postgresql - Automigrate in GORM database adds unwanted fields to SQL table
- arrays - 如何将地图存储到 Firestore 数组
- ios - Rest API 应该只添加新记录,或者应该通过删除来更新记录
- json - 使用 curl 将团队添加到存储库的正确方法
- batch-processing - 我们可以对批处理进行窗口化吗?
- clang-static-analyzer - 如何匹配指向空对象的指针?