即使将 contentHuggingPriority 设置为 defaultHigh 后,视图也会调整大小
我有一个垂直的 stackView。
bodyStackView.translatesAutoresizingMaskIntoConstraints = false
bodyStackView.axis = .vertical
bodyStackView.alignment = .fill
bodyStackView.distribution = .fill
bodyStackView.spacing = 8.0
bodyStackView.backgroundColor = .yellow
并添加两个/三个视图。
bodyStackView.addArrangedSubview(titleStackView)
bodyStackView.addArrangedSubview(priceStackView)
bodyStackView.addArrangedSubview(subscriptionInEligibleLabel)
titleStackView.setContentHuggingPriority(.defaultHigh, for: .vertical)
priceStackView.setContentHuggingPriority(.defaultLow, for: .vertical)
我希望最后一个或最底部的视图能够拉伸。 我已经设置了“ContentHuggingPriority”,但第一个或最上面的视图正在被拉伸。 我们如何控制这个?
I have a vertical stackView.
bodyStackView.translatesAutoresizingMaskIntoConstraints = false
bodyStackView.axis = .vertical
bodyStackView.alignment = .fill
bodyStackView.distribution = .fill
bodyStackView.spacing = 8.0
bodyStackView.backgroundColor = .yellow
and two/three views get added to it.
bodyStackView.addArrangedSubview(titleStackView)
bodyStackView.addArrangedSubview(priceStackView)
bodyStackView.addArrangedSubview(subscriptionInEligibleLabel)
titleStackView.setContentHuggingPriority(.defaultHigh, for: .vertical)
priceStackView.setContentHuggingPriority(.defaultLow, for: .vertical)
I want the last or the bottom-most view to stretch.
I have set the "ContentHuggingPriority", and yet the first or the top-most view is getting stretched.
How do we control this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前尚不清楚为什么您的
bodyStackView
中有 3 个堆栈视图,但假设您有充分的理由...您需要在 上设置
Content Hugging Priority
标签,不在堆栈视图上。It's not clear why you have 3 stack views in your
bodyStackView
, but assuming you have a valid reason...You need to set the
Content Hugging Priority
on the labels, not on the stack views.