Zitao Xiong
Zitao Xiong

Reputation: 976

Different size in iPhone 4&5 using Autolayout

Interface Build

I want to have a container view in the center as in the image, the requirement is:

I know how to do it via programming or IBOutlet. Is there a way to set it in Interface Builder Only?

Upvotes: 1

Views: 82

Answers (1)

matt
matt

Reputation: 535159

Not by merely setting auto layout constraints in a single nib/storyboard: their values are not conditional upon the runtime environment.

Your options probably are:

  • Programmatically adjust the constants of the constraints as the interface loads.

  • Maintain two different storyboards/nibs and load a different one depending upon runtime conditions (horrible)

  • Modify your desires, i.e. use a different set of constraints, one that give satisfactory results on both screen sizes. (This is, after all, the whole purpose of auto layout constraints!) For example you can specify that the width of the container view should be a certain percentage of the width of its superview (and that the container view is centered horizontally); this might not give you exactly the 25-vs.-35 values you specify, but it might be acceptable anyway.

Upvotes: 1

Related Questions