Frage

Interface Build

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

  • in iPhone 4 screen, the margin to left and right is 25
  • in iPhone 5 screen, the margin to left and right is 35

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top