user2982195 user2982195 - 3 years ago 269
Swift Question

Swift 4 backgroundColor bug?

I have a problem with transparency in my Views, especially with

UITableView
.

Just to make sure. I already have 3 years of experience with swift and this is the first time, I am getting this problem.

So in apple's docs it says the following:
backgroundColor

The view's background color.

Changes to this property can be animated. The default value is nil, which results in a transparent background color."

But when applying clear color to
backgroundColor
or
tableView.backgroundColor = UIColor.clear
, the background is still appearing white.

Is this a bug or a feature?

EDIT:

The tableView isn't the problem anymore. It is the cell within the tableView.
Already tried solutions are clearing the background color of all subviews. Nothing changed.

EDIT 29.09.17

Ok, I debugged my application and got this:

UICachedDeviceWhiteColor and cachedColor.

UICachedDeviceWhiteColor

A google searching also didn't help.

Edit 29.09.2017 Later that day ...

The problem occurs, when updating from swift 3 to swift 4.
I made a new project with swift 4, but it actually works fine.
Because it is a problem I have to solve. I will try some things and update this post from time to time.

Answer Source

Found the problem: When instantiating a variable which holds the view before displaying it, the background color of this view is white. The debugger calls this UICachedDeviceWhiteColor.

Why would you do that? If you instantiate the view before it is displayed, you can switch with a menu between different views very fast with "bringSubview(toFront: ...).

How to fix: To fix this you have to instantiate the view every time you want to show it.

Hope I could help some lost souls with this answer and Apple is going to fix this bug.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download