#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) UIButton *testbtn;
@end
@implementation ViewController
@synthesize testbtn;
- (void)viewDidLoad
{
[super viewDidLoad];
self.testbtn.frame = CGRectMake(10, 10, 50, 50);
self.testbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.testbtn setTitle:@"点击" forState:UIControlStateNormal];
[self.testbtn setTitle:@"松开" forState:UIControlEventTouchDown];
//处理按钮点击事件
[self.testbtn addTarget:self action:@selector(TouchDown)forControlEvents: UIControlEventTouchDownInside];
//处理按钮松开状态
[self.testbtn addTarget:self action:@selector(TouchUp)forControlEvents: UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
[self.view addSubview:self.testbtn];
}
- (void)TouchDown
{
//这里可以处理其他点击事件
NSLog(@"按钮点击了");
}
- (void)TouchUp
{
//这里可以处理其他松开事件
NSlog(@"按钮松开了");
}
@end