Git Product home page Git Product logo

bashimmerbutton's Introduction

BAShimmerButton

[![CI Status](http://img.shields.io/travis/Bryan Antigua/BAShimmerButton.svg?style=flat)](https://travis-ci.org/Bryan Antigua/BAShimmerButton) Version License Platform

Overview

Note:GIF QUALITY MAKES THE SHIMMER LESS SMOOTH (run the code for best display)


![example1](https://github.com/antiguab/BAShimmerButton/blob/master/readmeAssets/example1.gif) ![example4](https://github.com/antiguab/BAShimmerButton/blob/master/readmeAssets/example4.gif) ![example6](https://github.com/antiguab/BAShimmerButton/blob/master/readmeAssets/example10.gif)

A call-to-action button that offers shimmer, movement, and off/on functionality. Great for getting a users attention in multiple ways!


Requirements

  • Works on any iOS device

Example

To run the example project, clone the repo, and run pod install from the Example directory first.


Getting Started

Installation

BAShimmerButton is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "BAShimmerButton"

Simple Usage

Basic

To add a BAShimmerButton to your app, add the line:

BAShimmerButton *button = [[BAShimmerButton alloc] initWithFrame:self.view.frame];
[self addCircularMask:button];
[button showButtonWithAnimation:@YES];//@NO skips the animation

Note: circular mask added beforehand Note: You can skip the first line, if you added the button in IB

This creates the following animation/button:

example1

Advanced Usage

Listed below are examples of several properties that you can control.

Init

You can use initWithFrame: or simply adding the view in Interface Builder to use this button.

####showButtonWithAnimation:(bool)animated Calling this method shows the button, by passing in @NO, you will simply show the button. If you pass @YES, you'll see the following animation (same code in the basic section):

example1

####hideButtonWithAnimation:(bool)animated Similar to the one above, but the reverse:

example2

####toggleButton This will transiton the button from the on to off state, or vice versa. The IB action can be done like the example below:

- (IBAction)buttonPressed:(id)sender {
    BAShimmerButton *button = (BAShimmerButton*)sender;
    [button toggleButton];
}

You can then produce the following:

example3 example4

####wiggleButton To draw attention to your button, try this method:

BAShimmerButton *button = [[BAShimmerButton alloc] initWithFrame:self.view.frame];
[self addCircularMask:button];
[button showButtonWithAnimation:@NO];
[button wiggleButton];

which results in the following:

example5

Icon Image

An icon image can be set for the button with the iconImage property. This also results in a mask of the image for the off state (color of your choosing).

BAShimmerButton *button = [[BAShimmerButton alloc] initWithFrame:self.view.frame];
[self addCircularMask:button];
button.backgroundColor = [UIColor colorWithHex:0x420013];
button.shimmerColor = [UIColor colorWithHex:0xe33550];
button.iconImage = [UIImage imageNamed:@"icon"];
[button showButtonWithAnimation:@NO];//@NO skips the animation

This creates this button:

example10

IconOff ImageColor

For the off state of the icon above, you can set different off colors:

BAShimmerButton *button = [[BAShimmerButton alloc] initWithFrame:self.view.frame];
button.gradientSize = 0.3f;
button.backgroundColor = [UIColor colorWithHex:0x420013];
button.shimmerColor = [UIColor colorWithHex:0xe33550];
button.iconOffImageColor = [UIColor colorWithHex:0xfffffff];
button.iconImage = [UIImage imageNamed:@"icon"];
[button showButtonWithAnimation:@NO];

Note: Set before you set iconImage This creates the following view:

example11

Shimmer Duration

If you want the shimmering to last longer/shorter, you can edit the shimmerDuration property:

BAShimmerButton *button = [[BAShimmerButton alloc] initWithFrame:self.view.frame];
button.shimmerDuration = 1.0f;
[button showButtonWithAnimation:@NO];

This results in the following:

example6

Shimmer Color

You can also change the overall color of the shimmer by editing the shimmerColor property:

BAShimmerButton *button = [[BAShimmerButton alloc] initWithFrame:self.view.frame];
[self addRoundedSquareMask:button];
button.backgroundColor = [UIColor colorWithHex:0x22313F];
button.shimmerColor = [UIColor colorWithHex:0x3498db];
[button showButtonWithAnimation:@NO];

This creates the following effect:

example7

Shimmer Direction

By default, the animation goes from left to right in a diagonal direction. You can change the direction by setting the shimmerDirection property with any of the following:

  • BAShimmerDirectionTopToBottom
  • BAShimmerDirectionBottomToTop
  • BAShimmerDirectionLeftToRight
  • BAShimmerDirectionDiagonalLeftToRight
  • BAShimmerDirectionRightToLeft
  • BAShimmerDirectionDiagonalRightToLeft

Setting a new direction can be done like so:

BAShimmerButton *button = [[BAShimmerButton alloc] initWithFrame:self.view.frame];
button.shimmerDuration = BAShimmerDirectionTopToBottom;
[button showButtonWithAnimation:@NO];

This creates the following view:

example8

Gradient Size

the gradient size can be adjust with the gradientSize property. This value is betwee 0 and 1 and determines how wide the entire shimmer should be:

BAShimmerButton *button = [[BAShimmerButton alloc] initWithFrame:self.view.frame];
button.gradientSize = 0.3f;
[button showButtonWithAnimation:@NO];

This creates the following button:

example9

Author

Bryan Antigua, [email protected] - bryanantigua.com

License

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

bashimmerbutton's People

Contributors

antiguab avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.