如何在 Swift 中屏蔽 UIStackView? [英] How to mask a UIStackView in Swift?
问题描述
我知道 UIStackViews 的呈现方式与其余视图组件的呈现方式不同,因此它们无法被屏蔽.尽管如此,我相信还是有解决办法的.
I understand that UIStackViews are not rendered the same way the rest of view components are and thus they cannot be masked. Nonetheless I am sure there are work arounds.
有什么方法可以屏蔽 UIStackView?特别是将其他 UIStackViews 作为子视图的堆栈视图.
推荐答案
你不能,我相信.尽管它是 UIView
的子类,但您仍然无法为其设置 backgroundColor
.苹果说:
You can't, I believe. Although it's a subclass of UIView
, you still can't even set a backgroundColor
to it. Apple says:
UIStackView 是 UIView 的非渲染子类;也就是说,它不提供任何自己的用户界面.相反,它只是管理其排列视图的位置和大小.因此,某些属性(如 backgroundColor)对堆栈视图没有影响.同样,您不能覆盖 layerClass、draw(:) 或 draw(:in:).
The UIStackView is a nonrendering subclass of UIView; that is, it does not provide any user interface of its own. Instead, it just manages the position and size of its arranged views. As a result, some properties (like backgroundColor) have no effect on the stack view. Similarly, you cannot override layerClass, draw(:), or draw(:in:).
https://developer.apple.com/documentation/uikit/uistackview
这篇关于如何在 Swift 中屏蔽 UIStackView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!