Ωlo*_*stA 6 objective-c uitableview ios uibackgroundcolor ios13
我的 TableView 的标题在 iOS13 中显示不佳。不管我放什么颜色,它现在总是显示浅灰色......
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{ //Section color & style
UITableViewHeaderFooterView *v = (UITableViewHeaderFooterView *)view;
v.backgroundView.alpha = 1;
v.textLabel.textColor = sectionColor;
v.textLabel.font = sectionFont;
v.textLabel.numberOfLines = 1;
v.textLabel.minimumScaleFactor = 0.5;
v.textLabel.adjustsFontSizeToFitWidth = YES;
v.backgroundView.backgroundColor = [UIColor blueColor];
}
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为当我逐步停止调试器时,它在iOS13中向我显示了良好的图像,但在应用程序中却没有:
我在我的一个应用程序中注意到了同样的事情。然后在控制台看到一条日志信息:
不推荐在 UITableViewHeaderFooterView 上设置背景颜色。请改为将具有所需背景颜色的自定义 UIView 设置为 backgroundView 属性。
设置自定义UIView与所需的背景颜色和backgroundView的UITableViewHeaderFooterView解决了这个问题。
代码示例
class SomeHeaderView: UITableViewHeaderFooterView {
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
configure()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func configure() {
let backgroundView = UIView(frame: .zero)
backgroundView.backgroundColor = .blue
self.backgroundView = backgroundView
}
}
Run Code Online (Sandbox Code Playgroud)
这对我有用。
v.contentView.backgroundColor = .blue
Run Code Online (Sandbox Code Playgroud)
代替
v.backgroundView.backgroundColor = .blue
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3499 次 |
| 最近记录: |