Giter Site home page Giter Site logo

bfpaperbutton's Introduction

BFPaperButton

CocoaPods

A flat button inspired by Google Material Design's Paper theme.

Animated Screenshot

About

Now with smoother animations and more public properties for even easier customization!

BFPaperButton is a subclass of UIButton that behaves much like the new paper buttons from Google's Material Design Labs. All animation are asynchronous and are performed on sublayers. BFPaperButtons work right away with pleasing default behaviors, however they can be easily customized! The corner radius, tap-circle color, background fade color, and tap-circle diameter are all readily customizable via public properties.

BFPaperButtons come in 2 flavors, Flat or Raised. Flat BFPaperButtons have no shadow and will remain flat through all animations. Flat buttons can be transparent, in which case the background will also fade a little when tapped. Raised BFPaperButtons have a drop shadow that animates along with a tap, giving it the feeling of raising up with your touch. Raised BFPaperButtons do not look good with a clear background color since it will expose their shadow layer underneath.

By default, BFPaperButtons use "Smart Color" which will match the tap-circle and background fade colors to the color of the titleLabel. You can turn off Smart Color by setting the property, .usesSmartColor to NO. If you disable Smart Color, a gray color will be used by default for both the tap-circle and the background color fade. You can set your own colors via: .tapCircleColor and .backgroundFadeColor. Note that setting these disables Smart Color.

Note that setting the button type to Custom in the Storyboard is required to prevent the title from fading out on UIControlStateHighlighted.

Properties

UIColor *shadowColor

The UIColor for the shadow of a raised button. An alpha value of 1 is recommended as shadowOpacity overwrites the alpha of this color.

CGFloat loweredShadowOpacity

A CGFLoat representing the opacity of the shadow of RAISED buttons when they are lowered (idle). Default is 0.5f.

CGFloat loweredShadowRadius

A CGFLoat representing the radius of the shadow of RAISED buttons when they are lowered (idle). Default is 1.5f.

CGSize loweredShadowOffset

A CGSize representing the offset of the shadow of RAISED buttons when they are lowered (idle). Default is (0, 1).

CGFloat liftedShadowOpacity

A CGFLoat representing the opacity of the shadow of RAISED buttons when they are lifted (on touch down). Default is 0.5f.

CGFloat liftedShadowRadius

A CGFLoat representing the radius of the shadow of RAISED buttons when they are lifted (on touch down). Default is 4.5f.

CGSize liftedShadowOffset

A CGSize representing the offset of the shadow of RAISED buttons when they are lifted (on touch down). Default is (2, 4).

CGFloat touchDownAnimationDuration

A CGFLoat representing the duration of the animations which take place on touch DOWN! Default is 0.25f seconds. (Go Steelers)

CGFloat touchUpAnimationDuration

A CGFLoat representing the duration of the animations which take place on touch UP! Default is 2 * touchDownAnimationDuration seconds.

CGFloat tapCircleDiameterStartValue

A CGFLoat representing the diameter of the tap-circle as soon as it spawns, before it grows. Default is 5.f.

CGFloat tapCircleDiameter

The CGFloat value representing the Diameter of the tap-circle. By default it will be the result of MAX(self.frame.width, self.frame.height). tapCircleDiameterFull will calculate a circle that always fills the entire view. Any value less than or equal to tapCircleDiameterFull will result in default being used. The constants: tapCircleDiameterLarge, tapCircleDiameterMedium, and tapCircleDiameterSmall are also available for use. */

CGFloat tapCircleBurstAmount

The CGFloat value representing how much we should increase the diameter of the tap-circle by when we burst it. Default is 100.f.

CGFloat cornerRadius

The corner radius which propagates through to the sub layers. Default is 0.

UIColor *tapCircleColor

The UIColor to use for the circle which appears where you tap. NOTE: Setting this defeats the "Smart Color" ability of the tap circle. Alpha values less than 1 are recommended.

UIColor *backgroundFadeColor

The UIColor to fade clear backgrounds to. NOTE: Setting this defeats the "Smart Color" ability of the background fade. Alpha values less than 1 are recommended.

BOOL rippleFromTapLocation

A flag to set to YES to have the tap-circle ripple from point of touch. If this is set to NO, the tap-circle will always ripple from the center of the view. Default is YES.

BOOL rippleBeyondBounds

A flag to set to YES to have the tap-circle ripple beyond the bounds of the view. If this is set to NO, the tap-circle will be clipped to the view's bounds. Default is NO.

BOOL isRaised

A flag to set to YES to CHANGE a flat view to raised, or set to NO to CHANGE a raised view to flat. If you used one of the provided custom initializers, you should probably leave this parameter alone. If you instantiated via storyboard or IB and want to CHANGE from riased to flat, this is the parameter for you! Default is YES.

BOOL usesSmartColor

A flag to set YES to use Smart Color, or NO to use a custom color scheme. While Smart Color is the default (usesSmartColor = YES), customization is cool too.

Notes on RAISED vs FLAT and SMART COLOR vs NON SMART COLOR:

RAISED

Has a shadow, so a clear background will look silly. It has only a tap-circle color. No background-fade.

FLAT

Has no shadow, therefore clear backgrounds look fine. If the background is clear, it also has a background-fade color to help visualize the button and its frame.

SMART COLOR

Will use the titleLabel's font color to pick a tap circle color and, if the background is clear, will also pick a lighter background fade color.

NON SMART COLOR

Will use a translucent gray tap-circle and, if the background is clear, a lighter translucent gray background-fade color.

Usage

Add the BFPaperButton header and implementation file to your project. (.h & .m)

Creating a Flat BFPaperButton

BFPaperButton *flatPaperButton = [[BFPaperButton alloc] initWithFrame:rect raised:NO];

Creating a Raised BFPaperButton

BFPaperButton *raisedPaperButton = [[BFPaperButton alloc] initWithFrame:rect raised:YES];

Working Example

(Taken directly from example project.)

BFPaperButton *bfFlatSmart = [[BFPaperButton alloc] initWithFrame:CGRectMake(20, 20, 280, 43) raised:NO];
[bfFlatSmart setTitle:@"BFPaperButton Flat: Smart Color" forState:UIControlStateNormal];
bfFlatSmart.backgroundColor = [UIColor paperColorGray600];	// You can find this from my other library, BFPaperColors :)
[bfFlatSmart setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[bfFlatSmart setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[bfFlatSmart addTarget:self action:@selector(buttonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:bfFlatSmart];

Customized Example

(Taken directly from example project.)

BFPaperButton *circle2 = [[BFPaperButton alloc] initWithFrame:CGRectMake(116, 468, 86, 86) raised:YES];
[circle2 setTitle:@"Custom" forState:UIControlStateNormal];
[circle2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[circle2 setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[circle2 addTarget:self action:@selector(buttonWasPressed:) forControlEvents:UIControlEventTouchUpInside];
circle2.backgroundColor = [UIColor colorWithRed:0.3 green:0 blue:1 alpha:1];
circle2.tapCircleColor = [UIColor colorWithRed:1 green:0 blue:1 alpha:0.6];  // Setting this color overrides "Smart Color".
circle2.cornerRadius = circle2.frame.size.width / 2;
circle2.rippleFromTapLocation = NO;
circle2.rippleBeyondBounds = YES;
circle2.tapCircleDiameter = MAX(circle2.frame.size.width, circle2.frame.size.height) * 1.3;
[self.view addSubview:circle2];

CocoaPods

CocoaPods are the best way to manage library dependencies in Objective-C projects. Learn more at http://cocoapods.org

Add this to your podfile to add BFPaperButton to your project.

platform :ios, '7.0'
pod 'BFPaperButton'

License

BFPaperButton uses the MIT License:

Please see included LICENSE file.

bfpaperbutton's People

Contributors

abackys avatar bfeher avatar bryant1410 avatar bryanwayb avatar ndebei avatar readmecritic avatar yeahdongcn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bfpaperbutton's Issues

Font

How to change the font button?

hi~ I have found a problem with the button

I set the button isRase = FALSE
and my button was on a view which is smaller than screensize
I don't know why, everytime I hit it the first time it always have a ripple animate further than the bounce on the right....
I m using swift and the button is from storyboard.
can you help:)

circle grow beyond button's bounds

Is it possible to change the behavior of the growing circle to grow behind the mask of the button?
I have tried many places of the .m file with no luck.

Fast touch up inside

Hi,
Thank you for BFPaperButton, it looks great)
Could you help me some issue I got..
I am using BFPaperButtons inside UITableVIewCell,
when I push It fast, it stops and begins again not from correct state,
so it look like duplicate animation, pls see the gif file I attached.
And one more queation - is it possible not to "pause" animation
when you hold the button, but let it finish straight away?

thank u.

bfpapaerbuttonissue

layoutSubviews ignores enabled property

layoutSubviews ignores the enabled property, hence resets the appearance of the button to enabled while it may actually be and work as enabled.

My simple but dirty workaround is the following:

extension BFPaperButton {
    override public func layoutSubviews() {
        super.layoutSubviews()
        self.enabled = self.enabled
    }
}

tapCircleDiameter and different growth depending on longpress and normal touch

According to http://www.google.com/design/spec/animation/responsive-interaction.html#responsive-interaction-surface-reaction any touches made to a paper element (which has touch feedback) should do a quick droplet animation and quickly fade out. The animation bounds should be the view's bounds. This behaviour is already implemented. However, if you look at the "touch ripple: drag in and out" you can see that the droplet animation fills the entire view. This isnt the case in today's code. If i press and hold on a corner in a BFPaperButton only half of the view gets filled, probably due to the fact that the diameter of the ripple is never larger than the view's width. Which then means if clicking on a corner, you only fill half of the visible view.

I may have overlooked something, but it looks to me to be a small oversight on your behalf.

FEATURE REQUEST : Button Radius

I would like to put two buttons side by side and have the left side of button one be curved and the right side of button two be curved

Also if I could have the ability to specify if the radius us specified on specific corners

Button.RadiusTopLeft =
Button.RadiusTopRight =
Button.RadiusBottomLeft =
Button.RadiusBottomRight =

Also would it be possible to specify that the button is transparent with a border

Button.BorderWidth =
Button.BorderColor =

We are having to use a couple of images in a view and would like to replace them with your button

Animation on button doesn't work when button's parent ViewController is embed into a container view (i.e child viewController)

I have a viewcontroller, which has a container view, and this container view embeds(segue) a PageViewController, the 2nd page (which is another ViewController) in this PageViewController has the BFPaperButton. The animations don't work in this setup, but if I were to make the 2nd Page's ViewController as the Is Initial View Controller then the animations works perfectly, what is going on here??

TouchUpInside event is fired even if you touch up outside the button

Hi,

I noticed that if you "touch up" outside of the button (as if you want to cancel your touch), the "TouchUpInside" event is sometimes fired.

It happens if you "touch up outside" too close to the button (for example, in an area the growing disk would cover if it wasn't clipped).

Is there a way to limit the "touch up inside" event to the area of the visible button?

Sincerely,

Jery

Edit: I'm not sure but it may be a duplicate of issue #3, in that case, sorry for that.

Button Background Color

I got a problem when I init BFPapperButton from xib or storyboard.
The background color is always be blue color, why BFPapperButton will force background color to blue?

Is I need manually set the background color again?
screen shot 2014-10-12 at 3 29 00 am

Crash iOS 9.2 below archive by xcode 10.1

hello,
We found a bug at line 78, class: BFPapaerButton.m

  • (instancetype)initWithCoder:(NSCoder *)decoder
    {
    self = [super initWithCoder:decoder];
    if (self) {
    [self setupRaised:YES];
    }
    return self;
    }

please help me check and fix it

Run is not smooth

OC Code:
In a ViewController , the code >> [self.view addSubView:BFPaperButton ] , it is run normal and smooth.
I have a problem , In my ViewController has a UIScrollView , and some UIView in the UIScrollView , and put a BFPaperButton in the UIView. Run app and click the BFPaperButton ,it is not smooth.

Get rid of dots

Recently been facing this issue. Whenever i click on the button a dot shows up. like the second button in the GIF

ezgif com-video-to-gif 2

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.