UIView 应该是透明的但只显示白色
我有一个 UIViewController ,其中包含标签和按钮。我希望视图的背景是透明的,因此我将其设置为 clearColor
和 opaque = NO
。
但是,该视图始终显示白色背景。我该如何解决这个问题?
谢谢。
I have a UIViewController
which contains a label and button. I would like the background of the view to be transparent so I set it to clearColor
and opaque = NO
.
However, the view always displays a white background. How can I fix this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦一个新的视图控制器被推到堆栈的顶部,它后面的任何东西都会被隐藏,这样你就可以调整该视图的 Alpha 设置,但它后面没有任何东西可以显示(所以你会看到白色)。
您需要使用 UIView 来代替。我通常会继承 UIView 并按照我想要的方式自定义它,然后在需要使用它时实例化并将其添加为子视图:
Once a new view controller is pushed to the top of the stack, whatever is behind it gets hidden so you can adjust the alpha settings for that view but there's nothing to reveal behind it (so you will see white).
You need to use a UIView instead. I'd normally subclass UIView and customise it the way I want, then instantiate and add it as a subview whenever you need to use it:
抱歉,我没有足够的代表来评论 Rog 的答案,所以我将发布“另一个答案”。
尝试这个代码,看看它是否适合你:
老实说,我以前没有尝试过,因为我不需要这样做。但是当我从库中拖动一个新的 UIView 时,alpha 选项位于属性中。
希望这有帮助。
Sorry, I do not have enough rep to comment on Rog's answer, so I will post 'Another Answer'.
Try this code and see if it turns out well for you:
Honestly, I have not tried that before as I do not require doing so. But when I drag a new UIView from the library, alpha option is in the properties.
Hope this helps.