#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