Xamarin.iOS.AMViralSwitch
1.0.0
dotnet add package Xamarin.iOS.AMViralSwitch --version 1.0.0
NuGet\Install-Package Xamarin.iOS.AMViralSwitch -Version 1.0.0
<PackageReference Include="Xamarin.iOS.AMViralSwitch" Version="1.0.0" />
<PackageVersion Include="Xamarin.iOS.AMViralSwitch" Version="1.0.0" />
<PackageReference Include="Xamarin.iOS.AMViralSwitch" />
paket add Xamarin.iOS.AMViralSwitch --version 1.0.0
#r "nuget: Xamarin.iOS.AMViralSwitch, 1.0.0"
#:package Xamarin.iOS.AMViralSwitch@1.0.0
#addin nuget:?package=Xamarin.iOS.AMViralSwitch&version=1.0.0
#tool nuget:?package=Xamarin.iOS.AMViralSwitch&version=1.0.0
AMViralSwitch is a UISwitch subclass that 'infects' the parent view with the OnTintColor
when the switch is turned on.
Inspired by this Dribble by
Ramotion.
Usage
AMViralSwitch is a drop-in replacement of UISwitch:
- Use
AMViralSwitchinstead ofUISwitchas the class - Set the
OnTintColorproperty of the switch
The switch will automatically infect its superview with the selected color.
Animation
Animation Duration
Use AnimationDuration property to control the animation's speed:
switch.AnimationDuration = 1.5;
Animation Completion
You can listen for when either of the on and off animations complete:
switch.OnCompleted += delegate {
Console.WriteLine ("Animation On");
};
switch.OffCompleted += delegate {
Console.WriteLine ("Animation Off");
};
Animate Views
You can animate other views alongside the switch infection. Typically you'll want to change color to views or labels that are inside the same superview.
To do this, you can make use of the SetAnimationElementsOn and SetAnimationElementsOff
methods. You can animate CoreAnimation properties likes this:
switch.SetAnimationElementsOn (
AnimationElement.Layer (
someView.Layer,
"backgroundColor",
UIColor.Clear.CGColor,
UIColor.White.CGColor)
);
To animate the TextColor of an UILabel the syntax is slightly different:
switch.SetAnimationElementsOn (
AnimationElement.TextColor (someLabel, UIColor.White)
);
Follow the same principle to animate the tintColor of your UIButtons:
switch.SetAnimationElementsOn (
AnimationElement.TintColor (someButton, UIColor.White)
);
Finally, as the method accepts a params AnimationElement[], you can set and array, or
multiple:
switch.SetAnimationElementsOn (
AnimationElement.TintColor (someButton, UIColor.White),
AnimationElement.TextColor (someLabel, UIColor.White),
AnimationElement.Layer (
someView.Layer,
"backgroundColor",
UIColor.Clear.CGColor,
UIColor.White.CGColor)
);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| Xamarin.iOS | xamarinios is compatible. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 1,620 | 5/14/2018 |