簡體   English   中英

為什么[cell.detailTextLabel setBackgroundColor:[UIColor blackColor]]; 不行?

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

[cell.detailTextLabel setBackgroundColor:[UIColor blackColor]];

不起作用。 有什么辦法可以使其工作?

謝謝

UITableViewCell textLabeldetailTextLabel行為都不像普通的UILabel那樣。 這可能是因為出於性能原因,UITableViewCell會繪制其文本而不是使用UILabel 這導致行為不一致,因為單元格的繪圖將忽略backgroundColor屬性。

如果您想要的功能適合Apple工程師設計為由默認單元格處理的功能,請堅持使用默認的UITableViewCell 對於所有其他功能,請創建自己的UITableViewCell子類。

在表格視圖委托方法中設置

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

}

cell.detailTextLabel.textColor = [UIColor blackColor];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM