Latest 1.0.0
Homepage https://github.com/JZJJZJ/UIButton-Blocks
License MIT
Platforms ios 5.0
Authors

UIButton-Blocks

platform
GitHub license
CocoaPods

An UIButton Category replace SEL with Block.

Features

  • block syntax

Installation

Cocoapods(Recommended)

  1. Add pod 'UIButton+Blocks' to your Podfile.
  2. Run pod install

Manual

  1. Add all files under UIButton+Blocks/UIButton+Blocks to your project

Requirements

  • iOS 5.0 and greater
  • ARC/MRC

Examples

Code:

Objective-C


    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake((MDScreenWidth-100)*0.5, (MDScreenHeight-100)*0.5, 100, 100);
    [self.view addSubview:button];

    button.backgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:0.8];
    ;

    //default UIControlEventTouchUpInside
    ;

    /*
     ;
     */

Swift

You can use UIButton+Blocks in Swift projects too.
To do this, you must:

  1. Copy the relevant .m and .h files from the UIButton+Blocks src folder into your project
  2. If prompted to create a "bridging header", you should do so. If not prompted and if you don’t already have a bridging header, add one.

    For more information on bridging headers, see Swift and Objective-C in the Same Project.

  3. In your bridging header, add a line that says:
    #import "UIButton+Blocks.h"

If you do the above, you can then write Swift code that uses UIButton+Blocks. For example, in Swift 3.0 :

        let btn = UIButton(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: 100, height: 100)))
        btn.center = view.center
        btn.backgroundColor = UIColor.purple
        btn.setTitle("SwiftVC", for: UIControlState.normal)
        view.addSubview(btn)

        btn.handleTouchUpInsideEvent { (btn:UIButton?) in
            print("("SwiftViewController") (#function)")

        }

Credits

UIButton-Blocks was created by Jiang.Zijia in the development of MOMO.

License

UIButton+Blocks is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "UIButton+Blocks",
    "version": "1.0.0",
    "summary": "an extension of UIButton  on iOS",
    "description": "UIButton was created in a time before blocks, ARC, and judging by its namingn  Lets modernize this shizzle with some blocks goodness.",
    "license": "MIT",
    "authors": {
        "jiang.zijia": "[email protected]"
    },
    "homepage": "https://github.com/JZJJZJ/UIButton-Blocks",
    "requires_arc": false,
    "platforms": {
        "ios": "5.0"
    },
    "source": {
        "git": "https://github.com/JZJJZJ/UIButton-Blocks.git",
        "tag": "1.0.0"
    },
    "source_files": "UIButton+Blocks/*",
    "exclude_files": "Classes/Exclude"
}

Pin It on Pinterest

Share This