iOS:我的 TableView 标题的背景颜色在 iOS13 中不再改变

Ω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)

iOS12:
iOS12

iOS13: iOS13

这很奇怪,因为当我逐步停止调试器时,它在iOS13中向我显示了良好的图像,但在应用程序中却没有:

一步步 任何建议,提前致谢?

adr*_*aan 7

我在我的一个应用程序中注意到了同样的事情。然后在控制台看到一条日志信息:

不推荐在 UITableViewHeaderFooterView 上设置背景颜色。请改为将具有所需背景颜色的自定义 UIView 设置为 backgroundView 属性。

设置自定义UIView与所需的背景颜色和backgroundViewUITableViewHeaderFooterView解决了这个问题。

代码示例

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)


Hel*_*ova 7

这对我有用。

v.contentView.backgroundColor = .blue
Run Code Online (Sandbox Code Playgroud)

代替

v.backgroundView.backgroundColor = .blue
Run Code Online (Sandbox Code Playgroud)