Code Monkey home page Code Monkey logo

msblockbutton's Introduction

MSBlockButton

platform GitHub license CocoaPods GitHub stars

An UIButton Category replace SEL with Block.

Features

  • block syntax

Installation

Cocoapods(Recommended)

  1. Add pod 'MSBlockButton' to your Podfile.
  2. Run pod install

Manual

  1. Add all files under MSBlockButton to your project

Requirements

  • iOS 5.0 and greater
  • ARC/MRC

How To Use

Objective-C

        
    #import "MSBlockButton.h"
    
    CGFloat   width  = [UIScreen mainScreen].bounds.size.width;
    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake((width-100)*0.5, (width-100)*0.5, 100, 100);
    [self.view addSubview:button];
    
    button.backgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:0.8];
    [button setTitle:@"Blocks" forState:UIControlStateNormal];

    [button handleTouchUpInsideEventWithBlock:^(UIButton *sender) {
        NSLog(@"%s",__func__);

    }];
          

Swift

You can use MSBlockButton in Swift projects too. To do this, you must:

  1. Copy the relevant .m and .h files from the MSBlockButton 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.

  1. In your bridging header, add a line that says:
    #import "MSBlockButton.h"

If you do the above, you can then write Swift code that uses MSBlockButton. 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)")
         
     }

License

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

msblockbutton's People

Contributors

tempaccounta 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.