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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xamarin.iOS.AMViralSwitch" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xamarin.iOS.AMViralSwitch" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Xamarin.iOS.AMViralSwitch" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Xamarin.iOS.AMViralSwitch --version 1.0.0
                    
#r "nuget: Xamarin.iOS.AMViralSwitch, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Xamarin.iOS.AMViralSwitch@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Xamarin.iOS.AMViralSwitch&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Xamarin.iOS.AMViralSwitch&version=1.0.0
                    
Install as a Cake Tool

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:

  1. Use AMViralSwitch instead of UISwitch as the class
  2. Set the OnTintColor property 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 Compatible and additional computed target framework versions.
Xamarin.iOS xamarinios is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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,412 5/14/2018