繁体   English   中英

在UITableView单元格上显示UIButton

[英]Displaying a UIButton on UITableView cell

我想显示一个带有“!”的自定义按钮。 作为其在UITableView单元格内的文本。 代码是这样的:

UIButton *informationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[informationBtn setFrame:CGRectMake(10, 5, 55, 55)];
[informationBtn setTitle:@"!" forState:UIControlStateNormal];
[informationBtn addTarget:self action:@selector(popUpWindowWithMessage:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:informationBtn];

其中“单元格”定义为UITableViewCell实例。

但是该按钮没有出现在单元格上。 我应该怎么做才能显示按钮?

您的代码是正确的,并且似乎按钮在那里。 但是您看不到它。 更改按钮标题的颜色。 除了白色。 然后检查..

[informationBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

在设置按钮标题之后添加以上行。

如果您要将按钮添加到单元accessoryView ,则可以执行以下操作:

[cell setAccessoryView: informationBtn];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM