UITableView backgroundColor always white on iPad

后端 未结 16 1393
生来不讨喜
生来不讨喜 2020-12-07 21:35

I\'m working on a project. I have plenty of UITableViews which are set as clear color. Their views\' background color are set to my custom color and everything

相关标签:
16条回答
  • 2020-12-07 22:16

    You can fix this by making an appearance API setting in your appDelegate file :

    Swift:

    UITableViewCell.appearance().backgroundColor = UIColor.clearColor()
    
    0 讨论(0)
  • 2020-12-07 22:18

    This solve this issue for me

     func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        tableView.backgroundColor = UIColor.clear
    }
    
    0 讨论(0)
  • 2020-12-07 22:21

    SWIFT

    This was a happening to me, too. My table view in my SWRevealViewController appeared white on my iPad when it looked clear (which is how I wanted it with a background image) on my iPhone. I tried all of the above but this is what ended up working for me in my viewDidLoad().

    tableView.backgroundView = UIImageView(image: UIImage(named: "gray"))
    tableView.backgroundView?.backgroundColor = .clearColor()
    UITableViewCell.appearance().backgroundColor = .clearColor()
    
    0 讨论(0)
  • 2020-12-07 22:24

    Swift 3.1

    I've worked around this bug by placing this in my UITableViewCell subclass:

    When the cell is being loaded from the NIB file:

    override func awakeFromNib() {
        super.awakeFromNib()
        self.backgroundColor = UIColor.clear
    }
    

    and when the cell is being reused by the system

    override func prepareForReuse() {
        super.prepareForReuse()
        self.backgroundColor = UIColor.clear
    }
    

    iOS 10 is supposed to fix this issue in Interface Builder, as animeshporwal said.

    0 讨论(0)
  • 2020-12-07 22:26

    I have a transparent table view with semi-transparent table view cells. I set the table view background color to clear when I create the table. This works for all iOS/device combinations except iPad + iOS 8, where the background color remains white.

    For me, setting the cell's background color to semi-transparent and the content view background color to clear works, since I do it on each tableView(_ tableView: UITableView, cellForRowAt indexPath). The problem for me was only that the table view background remained white.

    I tried all combinations that I did find regarding this issue, but the only thing I actually needed to to was to set the table views background to transparent on each tableView(_ tableView: UITableView, cellForRowAt indexPath). Not super-intuitive, but at least it works. :P

    0 讨论(0)
  • 2020-12-07 22:27

    In my experience, some versions of iOS set UITableViewCell's backgroundColor before calling the delegate's tableView:willDisplayCell:forRowAtIndexPath:. Resetting back to your custom color in that method fixes it.

    0 讨论(0)
提交回复
热议问题