简体   繁体   中英

What is the iOS equivalent to WPF's Grid with star sizing?

In WPF, I can create a Grid with multiple column definitions where a single column can occupy the unused screen space with star sizing like so:

<Grid Height="50">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="50"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="50"/>
        <ColumnDefinition Width="50"/>
        <ColumnDefinition Width="50"/>
    </Grid.ColumnDefinitions>

    <Grid Grid.Column="0" Background="Red"/>
    <Grid Grid.Column="1" Background="Blue"/>
    <Grid Grid.Column="2" Background="Yellow"/>
    <Grid Grid.Column="3" Background="Pink"/>
    <Grid Grid.Column="4" Background="Green"/>
</Grid>

在此处输入图片说明

I need to replicate the same UI on iOS. I have looked into using UIStackView, but since I have less experience working with iOS, I'm not sure how to go about doing this. Is UIStackView the right choice or do I need to use another layout? How can this UI be replicated on iOS? Please note that this needs to be done programmatically.

Step 1. Drag a "Horizontal UIStackView" to your ViewController in IB, and set the Top, Left, Right and Height constraints.

Step2. Drag 5 UIViews in your StackViews, and set "Width" constraint to the 0th, 2nd, 3rd and 4th views. So every child view will have a fixed width expect the second one.
That's it.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM