Created
January 16, 2017 19:49
-
-
Save jfversluis/bc0a2a5ebca1ba07dad2cde12bb8f925 to your computer and use it in GitHub Desktop.
iOS and Android implementation of SwitchEffect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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