iOS_自定义Button
2015-10-17 09:07
295 查看
自定义Button
// // CustomButton.h // 自定义 button // // Created by Qianfeng on 15/10/10. // Copyright (c) 2015年 xyz. All rights reserved. // /** * 定制Button */ #import <UIKit/UIKit.h> @class CustomButton; typedef void (^ButtonBlock)(CustomButton *button); @interface CustomButton : UIButton - (void)addClickEventTouchUpInside:(ButtonBlock)block; @end
// // CustomButton.m // 自定义 button // // Created by Qianfeng on 15/10/10. // Copyright (c) 2015年 xyz. All rights reserved. // #import "CustomButton.h" @interface CustomButton() @property (nonatomic, copy) ButtonBlock block; @end @implementation CustomButton - (void)addClickEventTouchUpInside:(ButtonBlock)block { self.block = block; [self addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside]; } - (void)btnclick { if (self.block) { self.block(self); } } @end
// // ViewController.h // 自定义 button // // Created by Qianfeng on 15/10/10. // Copyright (c) 2015年 xyz. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end
// // ViewController.m // 自定义 button // // Created by Qianfeng on 15/10/10. // Copyright (c) 2015年 xyz. All rights reserved. // #import "ViewController.h" #import "CustomButton.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self customButton]; } - (void)customButton { CustomButton *btn = [[CustomButton alloc] initWithFrame:CGRectMake(20, 20, 100, 50)]; btn.backgroundColor = [UIColor redColor]; [btn setTitle:@"custombtn" forState:UIControlStateNormal]; [self.view addSubview:btn]; [btn addClickEventTouchUpInside:^(CustomButton *button) { NSLog(@"点击了自定义 按钮"); }]; } @end
相关文章推荐
- #在蓝懿学习iOSd的日子#
- 傻瓜式操作Nagios
- iOS开发——Handoff详解
- IOS正则表达式,很详细,值得一看!
- IOS - TableView上拉刷新数据后设置显示偏移(新数据置顶)
- 音乐/音效之工具类的封装
- iOS开发之多线程编程:GCD
- iOS:核心动画之转场动画CATransition
- IOS 同步操作 通信
- iOS:核心动画之动画组CAAnimationGroup
- IOS应用接iOS聚合支付(SDK集成说明)
- iOS 页面间几种传值方式(属性,代理,block,单例,通知)
- 整理iOS9适配中出现的坑(图文)
- iOS:核心动画之关键帧动画CAKeyframeAnimation
- ios申请真机调试( xcode 5)详细解析
- ios-数字格式化
- IOS开源项目指标
- iOS 懒加载
- iOS 当前应用或者浏览器中 唤起 手机其他应用
- ios-日期组件