UITableView backgroundColor在iPad上始终为白色

 木又的思念_740 发布于 2022-12-04 16:12

我正在做一个项目.我有很多UITableViews设置为清晰的颜色.他们的观点背景颜色设置为我的自定义颜色,iPhone上的一切都很好.

这个问题出现在iPad上!我几乎尝试了所有东西,但我UITableView的颜色是白色.

我检查了其他主题,例如:UITableView backgroundColor在iPad上总是灰色,但没有任何效果.另外,我的问题不是灰色,它像雪一样白!

可能是什么原因?

6 个回答
  • 这为我解决了这个问题

     func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        tableView.backgroundColor = UIColor.clear
    }
    

    2022-12-11 02:02 回答
  • 好消息:根据发布说明,适用于iOS 10:

    在iPad上运行时,现在可以遵守故事板中UITableViewCell的背景颜色设置.

    对于版本<10:

    我在iOS 8(8.3)中看到了这一点.即使在IB中我的细胞是"清晰的颜色",并且它们的内容视图是"清晰的颜色",它们将呈现为白色.一个不完美但合理的解决方案,因为它仍然需要来自IB的值:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        ...
        cell.backgroundColor = cell.contentView.backgroundColor;
        return cell;
    }
    

    似乎我的可重复使用的可重复使用的单元格在iPad上将其背景强制为白色.我能够使用视图层次结构调试器来确定这一点.

    一旦我这样做,我就可以使用表格的背景颜色,而不必设置背景视图,尽管这样也可以.

    2022-12-11 02:07 回答
  • 您可以通过在appDelegate文件中进行外观API设置来解决此问题:

    迅速:

    UITableViewCell.appearance().backgroundColor = UIColor.clearColor()
    

    2022-12-11 02:08 回答
  • 而不是设置背景颜色,尝试使用背景视图,如下所示:

    - (void)viewDidLoad {
        self.tableView.backgroundView = [UIView new];
        self.tableView.backgroundView.backgroundColor = [UIColor clearColor];
    }
    

    我有一些问题,使用backgroundColor并不总是产生效果,但设置背景视图反而很好.

    2022-12-11 02:13 回答
  • 我有一个桌面视图,里面有许多不同的单元格,每个单元格都有不同的颜色.

    @Ben Flynn的答案cell.backgroundColor = self.contentView.backgroundColor无法实现.原因是self.contentView.backgroundColor零,所以你所做的只是清楚了cell.backgroundColor = nil.

    基本上它是来自Xcode的错误(我想,是的,它糟透了!),cell.backgroundColor仍然有颜色,但它无法显示.

    经过一段时间的调试,基于@Ray W答案,这是我的解决方案.

    @impelement YouCustomCellClass
    
    - (void)awakeFromNib {
        [super awakeFromNib];
        self.backgroundColor = self.backgroundColor; // What the heck?? But it is.
    }
    
    @end
    

    2022-12-11 02:13 回答
  • 建立Ben Flynn的答案... cell.contentView背景颜色不一定等于cell.background颜色.在这种情况下,我发现这在解决更多情况下的iPad白色背景问题方面有效:

        - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
            ...
            cell.backgroundColor = cell.backgroundColor;
            return cell;
        }
    

    虽然声明看起来很荒谬和疯狂......它解决了这个问题.

    2022-12-11 03:08 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有