1

I have a fully functional app and I'm creating a new View Controller in Interface Builder with buttons and labels. I've laid out everything in the Interface Builder and used AutoLayout to make sure every component is in place. It's working very well on the iPhone 5s, but with the iPhone 6 and 6 Plus, my UIButtons are not resizing it's height to adjust to the bigger screens.

A screenshot would make help make more sense of this.

iPhone 5s enter image description here

iPhone 6 Plus enter image description here

The Update Me text is one UILabel. The Basic to the bottom PRO Unlimited is one UILabel. The buttons are separate UIButtons. The Restore Purchases is a UIButton and the final text on the bottom is a UILabel.

The constraints I have in place which matter are:

Basic Label

Trailing Space to Superview

Leading Space to Superview

Bottom Space to Restore Purchases UIButton

Top Space to UpdateMe UILabel

Buy 100 UIButton

Leading Space to Superview

Trailing Space to Buy Unlimited UIButton

Top Space to Top Layout

Bottom Space to Restore Purchases UIButton

Equal Width to Buy Unlimited UIButton

Buy Unlimited UIButton

Trailing Space to Superview

Leading Space to Buy 100

Top Space to Top Layout

Bottom Space to Restore Purchases UIButton

Equal Width to Buy 100

Restore Purchases UIButton

Trailing Space to Superview

Leading Space to Superview

Top Space Basic UILabel

Bottom Space to A One Off UILabel

Top Space to Buy Unlimited

Top Space to Buy 100

On the iPhone 5s, the Restore Purchases UIButton has a width of 268 and height of 30.

On the iPhone 6 Plus, the Restore Purchases UIButton has a width of 382 and height of 198, so clearly that's taking up a huge chunk of space which causes the UIButton to not increase.

What I would like to achieve is, every component in it's place as it is now, but on the iPhone 6 Plus, have the Buy 100 and Buy Unlimited UIButtons to increase in height with the width to stay the same.

Any guidance on this would really be appreciated!

amitsbajaj
  • 1,304
  • 1
  • 24
  • 59
  • ++Even if the button size increases It will look odd. You also have to increase the text/label size with increasing screen size. – Bista Mar 25 '15 at 10:09
  • Ah, that does make sense! Do you mean font size or actual size of the UILabels? I don't have a height constraint set anywhere, so I'm guessing it should increase with the increase in screen size but don't know if it's doing that right now? If I could make the font size bigger on the bigger screens and simultaneously increase the label size, that could work, but no idea how – amitsbajaj Mar 25 '15 at 10:12
  • I think both. I myself haven't tried increasing text/label myself. Let's wait for SO community to help. :). But try setting height constraint to each label, so that they can eat space to make layout good. – Bista Mar 25 '15 at 10:13
  • Thanks so much for writing in - I appreciate it and I hope the community can help me not go through another day of madness! :) – amitsbajaj Mar 25 '15 at 10:18
  • check this, [UILabel text not automatically resized using Auto Layout](http://stackoverflow.com/questions/17157778/uilabel-text-not-automatically-resized-using-auto-layout), Autolayout is done programmatically. – Bista Mar 25 '15 at 10:24
  • Thanks very much - that looks real promising! I've not done anything programatically but it does look like it could work – amitsbajaj Mar 25 '15 at 11:54

2 Answers2

0

In here you can add Aspect Ratio Constrains to your buttons.

enter image description here

DilumN
  • 2,889
  • 6
  • 30
  • 44
  • Thanks BC, but unfortunately I'm not using images. Just stock UILabels and UIButtons in Xcode; no images – amitsbajaj Mar 25 '15 at 10:12
  • 1
    Then you have to add Aspect Ratio constrains to both UIButtons. Did you try that?? – DilumN Mar 25 '15 at 10:15
  • Thanks BC - that sounds fancy and now I'm looking into what and how to set an Aspect Ratio :) – amitsbajaj Mar 25 '15 at 10:17
  • Thanks. I've set that up and it is working to some extent, the two buttons are increasing in size which is good, but it's still small and I wonder how to have the buttons increase. The aspect ratio is set to 62:17 for the height – amitsbajaj Mar 25 '15 at 11:55
0

Restore Purchases UIButton:

Remove below constrain

1.Top Space to Buy Unlimited 2.Top Space to Buy 100

Show "preview" the screens in "show assistant editor" option. Check the various screen size using preview option. If needed please remove and add the constraints in your screen. This preview option is very useful to resolve the auto layout constraints issue.

prabakaran iOS
  • 681
  • 7
  • 19
  • Thanks Prabakaran - that unfortunately doesn't work and I am using Preview to see the differences in each part – amitsbajaj Mar 25 '15 at 11:54
  • Hi lavanya, Please remove all dependency in top controls and add dependency in bottom controls and check in preview. Also do some minor adjustment in that constraints. Please refer this tutorials http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2. Thanks – prabakaran iOS Mar 25 '15 at 12:04