我设置了下面的UIButton (在tableview单元格中),目的是让它看起来像一个可点击的URL链接
UIButton *buttonUserName = [UIButton buttonWithType:UIButtonTypeCustom];
buttonUserName.frame = CGRectMake(10, 10, 280, 20);
[buttonUserName setTitle:@"test" forState:UIControlStateNormal];
[buttonUserName setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[buttonUserName setEnabled:YES];
buttonUserName.userInteractionEnabled = YES;
[buttonUserName addTarget:self action:@selector(user:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:buttonUserName];按钮和标题确实出现了,但当我点击它时,它没有点击效果(视觉上)。我错过了什么吗?
发布于 2012-03-05 12:14:08
将所需的可视反馈设置为按钮状态UIControlStateHighlighted
例如: title color
[buttonUserName setTitleColor:[UIColor redColor] forState: UIControlStateHighlighted];以及其他一些标题、背景图像、图像等。
发布于 2012-03-05 12:23:57
添加以下内容:
[cell.contentView bringSubviewToFront:buttonUserName];我想你会将任何其他视图重叠到按钮上
发布于 2012-03-05 11:57:10
尝试在其中放置一些UIAlert或NSLog,以查看是否获得了点击事件。因为在用户点击你的按钮之后,事件会转到(IBAction)user:(id)sender
https://stackoverflow.com/questions/9561427
复制相似问题