首页 > 解决方案 > Alignment in horizontal stack view of label and switch

问题描述

I'm trying to use a horizontal stack view inside of a vertical stack view to create a series of labels and switches for settings. I want the switches to line up vertically but their position changes based on the length of text in the label when have fill proportionally selected. Other choices either throw the switch all the way to the right margin or Fill Equally doesn't leave enough space for a longer label and too much white space to the right of the button.

Thanks

标签: iosstoryboard

解决方案


UIStackView 正在根据 UIView 安排其子视图intrinsicContentSize

- (CGSize)intrinsicContentSize {
    return CGSizeMake(width, height);
} 

不要忘记,您应该避免在运行时更改此大小。


推荐阅读