Giter Club home page Giter Club logo

cmdawesomebutton's Introduction

CMDAwesomeButton

This is my button subclass. It is awesome.

It is powered by one method:

- (void)setValue:(id)value forKeyPath:(NSString *)keyPath state:(UIControlState)state;

This lets you set any value for any keypath for the given control state.

It also has convenience setters for a few common tasks:

- (void)setBackgroundColor:(UIColor *)color forState:(UIControlState)state;
- (void)setBorderColor:(UIColor *)color forState:(UIControlState)state;
- (void)setBorderWidth:(CGFloat)width forState:(UIControlState)state;
- (void)setCornerRadius:(CGFloat)radius forState:(UIControlState)state;

Awesome right?

There's also a handy backgroundView property. You can put whatever you want there. Let's say you have a gradient view. Do something like this:

CMDAwesomeButton *gradientButton = [CMDAwesomeButton new];

SAMgradientView *gradientView = [SAMGradientView new];
gradientView.backgroundColor = [UIColor clearColor];
gradientButton.backgroundView = gradientView;

[gradientButton setValue:@[
    [UIColor colorWithRed:0.145 green:0.769 blue:0.757 alpha:1.000],
    [UIColor colorWithRed:0.196 green:0.678 blue:0.800 alpha:1.000]
] forKeyPath:@"backgroundView.gradientColors" state:UIControlStateNormal];
[gradientButton setValue:@[
    [UIColor colorWithRed:0.145 green:0.769 blue:0.757 alpha:0.5],
    [UIColor colorWithRed:0.196 green:0.678 blue:0.800 alpha:0.5]
] forKeyPath:@"backgroundView.gradientColors" state:UIControlStateHighlighted];

Boom. (SAMGradientView is great. I use it in all my apps.)

If you would like more convenience setters feel free to send me a pull request!

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.