UIFrameView水平居中

问题描述 投票:1回答:1

我正在尝试通过水平的UIStack视图实现以下目标:

将显示未知数量的复选框(最多5个)。我希望它们像下面(两张单独的图像)一样居中并均匀分布:

5 centered checkboxes

2 centered checkboxes

如果我只需要一个复选框,它将居中。

这是我到目前为止所得到的:

5 distributed checkboxes

2 distributed checkboxes

我现在很清楚,在堆栈视图的左侧和右侧固定了2个复选框,其余复选框根据请求的内容进行了分配和间隔。

我希望一切都从堆栈视图的中心分发。

这里是显示堆栈视图配置的代码:

UIStackView firstFiveCheckboxesStackView = new UIStackView
{
     TranslatesAutoresizingMaskIntoConstraints = false,
     Axis = UILayoutConstraintAxis.Horizontal,
     Distribution = UIStackViewDistribution.EqualSpacing,
     Alignment = UIStackViewAlignment.Center,
     Spacing = 10
};
c# ios xamarin.ios uistackview
1个回答
0
投票

尝试使用UIStackViewAlignment.Fill并将所有复选框包装在UIView中。

© www.soinside.com 2019 - 2024. All rights reserved.