Maison > Questions et réponses > le corps du texte
UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 38, 100, 38)];
[btn2 setTitle:@"添加好友" forState:UIControlStateNormal]; btn2.titleLabel.font = [UIFont systemFontOfSize:16];
[btn2 addTarget:self action:@selector(btn2Click:) forControlEvents:UIControlEventTouchDown];
之前可以触发, 现在不知是何原因不能触发了?
ringa_lee2017-04-17 14:26:40
首先更改
[btn2 addTarget:self action:@selector(btn2Click:) forControlEvents:UIControlEventTouchUpInside];
这样还不行的话,检查下父视图的属性 User Interaction Enabled,或者查看btn2Click:方法
伊谢尔伦2017-04-17 14:26:40
改成如下代码再试试
UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 38, 100, 38)];
[btn2 setTitle:@"添加好友" forState:UIControlStateNormal]; btn2.titleLabel.font = [UIFont systemFontOfSize:16];
[btn2 addTarget:self action:@selector(btn2Click:) forControlEvents:UIControlEventTouchUpInside];
天蓬老师2017-04-17 14:26:40
麻烦 forControlEvents
的枚举改成:UIControlEventTouchUpInside
另外button 有intrinctSize。你是否点在这个范围内