-(void)addNewTarget:(id)target Action:(SEL)action;
@property(nonatomic,assign)id target;
@property(nonatomic,assign)SEL action;
MyButton.m
-(void)addNewTarget:(id)target Action:(SEL)action{
self.action = action;
self.target = target;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.target performSelector:self.action withObject:self];
}
MyButton *myButton = [[MyButton alloc]initWithFrame:CGRectMake(100, 100, 150, 40)];
[myButton addNewTarget:self Action:@selector(clicl:)];
实现自定义的方法
-(void)clicl:(MyButton *)button{
NSLog(@"实现点击效果");
}