Question

I have three views that are in a horizontal line. The middle view is centered horizontally while the other two are the same distance away, one to the left and one to the right.

When I rotate the screen to landscape, I want the middle view to stay centered horizontally, and I want the other two views to stay the same distance away from the center.

Is there an easy way to do this in Xcode?

Was it helpful?

Solution

This is harder to do with springs & struts and setting the frame, and is simpler to handle with Auto Layout constraints, if you can use those in your app. See this video from Justin Williams for a good overview of why.

If you need to stick with springs & struts and setting the frame in code, for some reason, you'll have to recompute the center of the super view, and then use that to set the .center of your subview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top