开发者

Why does [cell.detailTextLabel setBackgroundColor:[UIColor blackColor]]; not work?

开发者 https://www.devze.com 2023-01-20 22:58 出处:网络
[cell.detailTextLabel setBackgroundColor:[UIColor blackColor]]; doesn\'t wor开发者_开发问答k. Any way to make it work?
[cell.detailTextLabel setBackgroundColor:[UIColor blackColor]];

doesn't wor开发者_开发问答k. Any way to make it work?

Thanks


The UITableViewCell textLabel and detailTextLabel both don't behave like normal UILabel's. This probably is because a UITableViewCell draws it's text instead of using a UILabel for performance reasons. This results in inconsistent behaviour because the backgroundColor property is ignored by the cell's drawing.

Stick with the default UITableViewCell if your desired functionality fits within what the Apple engineers have designed to be handled by a default cell. For all other functionality create your own subclass of UITableViewCell.


set this in table view delegate method

- (void)tableView: (UITableView*)tableView   willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath {
[cell.detailTextLabel setBackgroundColor:[UIColor blackColor]];

}


cell.detailTextLabel.textColor = [UIColor blackColor];

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号