简体   繁体   中英

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

在此处输入图片说明

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

在此处输入图片说明

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

在此处输入图片说明

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

在此处输入图片说明

Adding a height constraint solved the problem.

在此处输入图片说明

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

在此处输入图片说明

您的超级视图是否具有清晰的颜色,然后将其更改为黑色它将解决您的问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM