当当前对齐为中心时

发布于 2025-02-09 03:38:39 字数 1093 浏览 2 评论 0 原文

我有一种情况,我需要根据条件的条件,尾随和中心来编程以编程方式更新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

我在这里附上

任何帮助将不胜感激

I have a case in which I need to update Stackview alignment programmatically based on the condition i.e leading, trailing, and center

It is working as expected when I change alignment from leading to trailing or vice versa but it is not working if change alignment from center to leading or trailing.

I have set default StackView property as per below:

stackView.alignment = .trailing
stackView.axis = .vertical
stackView.distribution = .fill

I am trying to change alignment using UISegment control, 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

I am attaching here video link for your reference.

Any help would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的黑色迷你裙 2025-02-16 03:38:39

我一定会将其归类为“错误”。

如果您想要快速,简单的工作,请添加一个空 uiview - 被限制在size 0x0 - 到堆栈视图:

​设置:

由于添加的视图没有高度,并且堆栈视图间距为 0 ,它将看不到,并且不会影响堆栈视图的尺寸。

I would definitely classify this as a "bug."

If you want a quick, easy work-around, add an empty UIView - constrained to size 0x0 - to the stack view:

enter image description here

Stack view settings:

enter image description here

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文