How to divide UIView in to three even sized subviews horizontally in XCODE?

前端 未结 5 1369
你的背包
你的背包 2021-01-13 23:51

I Have to divide a UIView horizontally into three even sized subviews using Xcode. I tried to use constraints. I got the following result.

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-14 00:48

    I would suggest to use UIStackView. If you never use it, it is like a container of things (UIViews in your case), and you can set it to use equally proportions (Distribution: Fill Equally). This means that for every element you drag into the stackview, it will set it width proporcionally.

    If you drag 1 item, it will have 100% of the UIStackView width.

    If you drag 2 items, each one will have 50% of the width.

    If you drag 3, each one will have 33%. And so on.

    You can even use a vertical or horizontal stackview. I find it very usefull. Here you have the official documentation: https://developer.apple.com/reference/uikit/uistackview

提交回复
热议问题