UIButton block equivalent to addTarget:action:forControlEvents: method?

后端 未结 9 1222
旧巷少年郎
旧巷少年郎 2020-11-29 20:58

I looked around, but couldn\'t find this on the internet, nor anywhere in the Apple docs, so I\'m guessing it doesn\'t exist.

But is there a iOS4 blocks equivalent A

9条回答
  •  旧时难觅i
    2020-11-29 21:33

    I created a library to do just this!

    It supports UIControl (UIButton), UIBarButtonItem, and UIGestureRecognizer. It is also supported using CocoaPods.

    https://github.com/lavoy/ALActionBlocks

    // Assuming you have a UIButton named 'button'
    [button handleControlEvents:UIControlEventTouchUpInside withBlock:^(id weakControl) {
        NSLog(@"button pressed");
    }];
    

    Install

    pod 'ALActionBlocks'
    

提交回复
热议问题