gpt4 book ai didi

ios - 不同的单元格背景颜色取决于 iOS 版本(4.0 到 5.0)

转载 作者:技术小花猫 更新时间:2023-10-29 11:18:22 26 4
gpt4 key购买 nike

我有一个自定义分组的 UITableViewCell,上面有几个 UILabel。由于 UITableViewCell 的背景颜色过去是纯白色,它与 UILabels 的默认背景颜色相匹配,因此 UILabel 框不可见..

更新到 iOS 5.0 后,我注意到现在分组的 UITableViewCells 的默认背景颜色更灰白色(实际上是#f7f7f7),因此 UILabels 的框架以丑陋的方式可见..

那么,当需要在不同的 iOS 版本之间变化时,设置 UILabel 背景颜色的最佳方式是什么?我知道我可以使用 opaque = NO 和 [UIColor clearColor],但出于性能原因我更愿意绘制 UILabel 的背景。

最佳答案

在委托(delegate)方法 tableView:willDisplayCell: 中,UITableViewCell 会将背景颜色设置为白色,或者在 iOS 5 中为灰色。

您可以更改所有 subview 的所有 backgroundColor

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
for (UIView* view in cell.contentView.subviews) {
view.backgroundColor = cell.backgroundColor;
}
}

关于ios - 不同的单元格背景颜色取决于 iOS 版本(4.0 到 5.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7733828/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com