Sebastian Dine
Sebastian Dine

Reputation: 999

iOS UIView background color gets invisible/transparent when adding constraints

I am building a UI where the background color of the main view is black and the background color of some UIView elements within the View are white. The colors get displayed properly when there is not UI constraint for the UIView elements. However, when I add any constraint to the UIView elements, the white background seems to get transparent. I assume that it is still there, since UI constraints of other elements in relative to this UIView element are still on their correct place.

This is the structure of my UI (without UI constraints):

enter image description here

And this is how it looks like in simulator (iPhone XR 12.2):

enter image description here

Now I add the following UI constraints to the UIView element view_config

enter image description here

When I run the app in simulator again, now the background color of view_config is transparent.

enter image description here

Upvotes: 1

Views: 710

Answers (2)

Neeraj
Neeraj

Reputation: 91

is your super view have clear color then change it to black color it will fix your problem

Upvotes: 0

Sebastian Dine
Sebastian Dine

Reputation: 999

Adding a height constraint solved the problem.

enter image description here

Even better than a static height constraint would be a relative constraint so that the height of element is calculated implicitly.

enter image description here

Upvotes: 1

Related Questions