View on GitHub

ASOAnimatedButton

ASOAnimatedButton is a storyboard-friendly library to animate button to have a two-state or bounce effect.

Download this project as a .zip file Download this project as a tar.gz file

TwoStateButtonExample

This App shows a toggle button which change its image every time it is tapped. A fade-out effect is set between its state changes.

ASOTwoStateButton animation preview

How To

Integrate the library

Add these lines in the Podfile:

platform :ios, '7.0'
pod 'ASOAnimatedButton'

Or add these lines if only the ASOTwoStateButton library is going to be used in the project:

platform :ios, '7.0'
pod 'ASOAnimatedButton/TwoStateButton'

Storyboard

Define each image name as values of OnStateImageName and OffStateImageName keys in User Defined Runtime Attributes of the ASOTwoStateButton object.

ASOTwoStateButton storyboard preview

Implementation

Initialise the 'Two-State Button'

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    // Set the 'Two-State Button'
    [self.twoStateButton initAnimationWithFadeEffectEnabled:YES]; // Set to 'NO' to disable Fade effect between its two-state transition
}

Add custom actions for each state

- (IBAction)twoStateButtonAction:(id)sender {
    if ([sender isOn]) {
        // Add actions related to the On-State

    } else {
       // Add actions related to the Off-State

    }
}

Controls

Control whether fade effect is enabled between state changing

@property (nonatomic) BOOL isFadeEffectEnabled;

Control the effect duration between state changing

@property (nonatomic) NSTimeInterval effectDuration;

Getting Help

If you need help using ASOTwoStateButton, please post a question on StackOverflow with the "ASOAnimatedButton" tag.

If you think you found a problem with ASOTwoStateButton, please post an issue. A sample project or fork of any of the examples demonstrating the problem will be helpful.

Author

Agus Soedibjo. Copyright (c) 2014 Agus Soedibjo, contact@soedibjo.com

License

ASOAnimatedButton is available under the MIT license. See the LICENSE file for more info.