I am currently building a UI component for an iOS application. Generally, the component is supposed to be 350pt in width, which I set up inside the component using auto layout:
self.widthAnchor.constraint(equalToConstant: 350.0).isActive = true
Now, if there is not enough space (due to other constraints outside of the component), I want the component to become smaller, but not fluidly - I want the component to alternate between two possible sizes only - 350pt normally and 300pt width if there is no room to fit 350pt. Is this achievable somehow?
Example project:
https://www.icloud.com/iclouddrive/055TkWS8aLqDhFDOPi-7qi8EA#LayoutExample.zip
I created a very simplistic example project to illustrate the problem. It contains a custom component (MyComponent
), which is a stack view with four buttons. This component is embedded in the main view controller and auto layout is setup to ensure it doesn't flow out of the screen.
This works well on larger devices, but the component is too large for the screen of iPhone SE and iPhone 4. In these cases, I would like the component to become another size (in the project, the component is 500pt regularly and should be 300pt on smaller devices).
Reasons
The reason I am looking for this behaviour are pretty much all design related. This component is not supposed to exist in a variety of sizes, but only in two specific sizes - a "normal" size and a smaller size for cases where the normal size doesn't fit.