0

I built my views in Interface Builder for iPhone 4 dimensions. I thought that the Autoresize Constraints in iOS 6 will take care of the resizing automatically. The screenshot shows the Top Space constraint that Xcode added automatically. It says that the relationship between the top and the bottom orange view must be 332 points.

top space constraint

When viewed in iPhone 5, the orange button is stretched all the way to the bottom as you can see in the screenshot below.

enter image description here

When changing the relation to Greater Than or Equal, the view does not change and remains the same. When removing the constant to make it Auto, the view is stretched across the entire screen. How do I specify a constraint were the height is 44 points and at the bottom?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
darksky
  • 20,411
  • 61
  • 165
  • 254

2 Answers2

0

Try adding your own contraints (user constraint), In Auto Layout for each object there must always be enough constraints to determine both its position and size on different devices screen.

Interface Builder automatically creates constraints for you as soon as you place a view in a layout. Try placing your views along IB’s automatic guides to help it guess correctly which layout you want.

Prior to Xcode 4 it was done by setting the springs and struts from the Interface Builder and the springs and struts model is still the default, so for every programmatically created view that you want to use autolayout with, dont forget to call

setTranslatesAutoresizingMaskIntoConstraints:NO.
Sarim Sidd
  • 2,166
  • 2
  • 22
  • 31
0

Don't have a constraint to the top of the superview. Pin it to the bottom of the superview, and fix the height to 44, then delete the constraint linking it to the top of the view.

You achieve the pinning by selecting the view in question and using the pinning menu in interface builder (the floating menu with three icons on it, or editor-->pin from the menu bar).

To move between 3.5 and 4 inch displays, you need to link content to the correct edge of the superview. Stuff at the bottom should be stuck to the bottom.

I have written about constraint editing in interface builder here if you're interested.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • I cannot delete the top space constraint (it's purple). I just pinned it to the bottom, height remained 44, and I cannot delete the top view constraint, but I'm still having the same issue on 4-inch displays. How can I remove that top constraint? I set it it as Auto but as soon as I resize it to 44 and pin it to the bottom superview, the same old 323 top of the view constraint comes back automatically. Any suggestions? – darksky Jun 30 '13 at 16:16
  • If you have pinned the bottom of the view to the bottom of the superview, and the height to 44, you should be able to delete the top constraint. You may have to promote it to a user constraint first. IB only adds constraints if you drag and drop views (in which case it drops everything and makes brand new constraints) or if you haven't specified enough constraints to unambiguously define the layout. – jrturton Jun 30 '13 at 17:37
  • So don't size to 44 by dragging and dropping, at least not without setting everything else up after. Use the pinning menu to define the height, then edit the constraints in the inspector. – jrturton Jun 30 '13 at 17:39