I Have to divide a UIView
horizontally into three even sized subviews using Xcode
. I tried to use constraints.
I got the following result.
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