你能给 UIStackView 边框吗? [英] Can you give UIStackView borders?

查看:36
本文介绍了你能给 UIStackView 边框吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的 ViewController 边框中提供 5 个单独的 UIStackViews.我给了他们每个人一个 IBOutlet,然后在 viewDidLoad 中调用它们以使用 layer 属性,但无济于事.是否无法以编程方式提供堆栈视图边框?

I'm trying to give 5 separate UIStackViews in my ViewController borders. I gave each of them an IBOutlet and then called them in viewDidLoad to use the layer property but to no avail. Is it not possible to give stack views borders, programatically?

代码:

@IBOutlet weak var stackView1: UIStackView!
@IBOutlet weak var stackView2: UIStackView!
@IBOutlet weak var stackView3: UIStackView!
@IBOutlet weak var stackView4: UIStackView!
@IBOutlet weak var stackView5: UIStackView!

override func viewDidLoad() {
    super.viewDidLoad()

    stackView1.layer.borderWidth = 5
    stackView2.layer.borderWidth = 5
    stackView3.layer.borderWidth = 5
    stackView4.layer.borderWidth = 5
    stackView5.layer.borderWidth = 5   
}

推荐答案

很遗憾,这无法完成.UIStackView 的不寻常之处在于它是一个非渲染"视图,它执行布局(使用自动布局约束)但不显示自身.它有一个和所有 UIViews 一样的层,但它被忽略了.

Unfortunately this can't be done. UIStackView is unusual in that it is a "non-rendering" view which performs layout (using Auto Layout constraints) but does not display itself. It has a layer like all UIViews, but it's ignored.

请参阅管理堆栈视图的外观"下的Apple 文档:

See the Apple doc under "Managing the Stack View's Appearance":

UIStackView 是 UIView 的非渲染子类.它不是提供它自己的任何用户界面.相反,它只是管理其排列视图的位置和大小.因此,某些属性(如 backgroundColor)对堆栈视图没有影响.相似地,您不能覆盖 layerClass、drawRect: 或 drawLayer:inContext:

The UIStackView is a nonrendering subclass of UIView. 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 affect on the stack view. Similarly, you cannot override layerClass, drawRect:, or drawLayer:inContext:

这篇关于你能给 UIStackView 边框吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆