当当前对齐为中心时
我有一种情况,我需要根据条件的条件,尾随和中心来编程以编程方式更新stackView对齐,
当我将对齐方式从导致尾随或反之亦然时,它正在按预期工作,但是如果从中心变更对齐,则无法正常工作。领导或落后。
我已经设置了下面的默认stackView属性:
stackView.alignment = .trailing
stackView.axis = .vertical
stackView.distribution = .fill
我正在尝试使用UISEGREMT CONTROR更改对齐,here is a sample code link
@IBAction func segment(_ sender: UISegmentedControl) {
switch (sender.selectedSegmentIndex) {
case 0:
stackView.alignment = .leading
case 1:
stackView.alignment = .center
case 2:
stackView.alignment = .trailing
default:
break
}
}
Problem: Button width is automatically increasing when I change alignment from center to leading or trailing programmatically even if I have set a fixed width to the button
我在这里附上
任何帮助将不胜感激
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我一定会将其归类为“错误”。
如果您想要快速,简单的工作,请添加一个空
uiview
- 被限制在size0x0
- 到堆栈视图:设置:
由于添加的视图没有高度,并且堆栈视图间距为
0
,它将看不到,并且不会影响堆栈视图的尺寸。I would definitely classify this as a "bug."
If you want a quick, easy work-around, add an empty
UIView
- constrained to size0x0
- to the stack view:Stack view settings:
Because the added view has no Height, and the stack view spacing is
0
, it will not be visible and will not affect the dimensions of the stack view.