[cell.detailTextLabel setBackgroundColor:[UIColor blackColor]];
不起作用。有什么办法让它工作吗?
谢谢
[cell.detailTextLabel setBackgroundColor:[UIColor blackColor]];
不起作用。有什么办法让它工作吗?
谢谢
UITableViewCell
textLabel
和两者的detailTextLabel
行为都不像正常UILabel
的。UILabel
这可能是因为 UITableViewCell出于性能原因绘制它的文本而不是使用 a 。这会导致不一致的行为,因为单元格的绘图忽略了 backgroundColor 属性。
UITableViewCell
如果您想要的功能符合 Apple 工程师设计的由默认单元处理的功能,请坚持使用默认值。对于所有其他功能,请创建您自己的 UITableViewCell 子类。
在表视图委托方法中设置它
- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath {
[cell.detailTextLabel setBackgroundColor:[UIColor blackColor]];
}
cell.detailTextLabel.textColor = [UIColor blackColor];