Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created January 16, 2017 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfversluis/bc0a2a5ebca1ba07dad2cde12bb8f925 to your computer and use it in GitHub Desktop.
Save jfversluis/bc0a2a5ebca1ba07dad2cde12bb8f925 to your computer and use it in GitHub Desktop.
iOS and Android implementation of SwitchEffect
// Android SwitchEffect.cs
public class SwitchEffect : PlatformEffect
{
Xamarin.Forms.Color _trueColor;
protected override void OnAttached ()
{
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean) {
_trueColor = (Xamarin.Forms.Color)Element.GetValue (SwitchColorEffect.TrueColorProperty);
((SwitchCompat)Control).ThumbDrawable.SetColorFilter (_trueColor.ToAndroid (), PorterDuff.Mode.Multiply);
}
}
protected override void OnDetached ()
{
}
}
// iOS SwitchEffect.cs
public class SwitchEffect : PlatformEffect
{
Xamarin.Forms.Color _trueColor;
protected override void OnAttached ()
{
_trueColor = (Xamarin.Forms.Color)Element.GetValue (SwitchColorEffect.TrueColorProperty);
(Control as UISwitch).OnTintColor = _trueColor.ToUIColor ();
}
protected override void OnDetached ()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment