0

In my app, I have four square buttons that I want to proportionally change size for each different screen size that adhere to the margin constraints set. However, I am unable to set a proportional margin size between the trailing edge of the view controller and the leading part of a button, it requires a hard number. How do I get around this. Because i want the app to fit all screen sizes I want the autolayout to measure everything in terms of screen proportions but this doesn't seem possible.

Any advice on how to get around this issue would be much appreciated!

Heres an image of my situation

Thank you

  • use collectionview – SPatel Dec 19 '18 at 12:59
  • 1
    Can you please be more clear what you want to achieve? – Emre Önder Dec 19 '18 at 13:00
  • Do you have 4 buttons or 9 buttons? Or are you asking for both cases? Do you want the buttons equally distributed? Or do you want them to change size? – DonMag Dec 19 '18 at 13:04
  • I want these buttons to be equally distributed on the bottom half of the screen. Obviously for one screen size I can hard code numbers, but I want the buttons and button margins to proportionally change for different screen sizes. For both cases would be ideal! Thanks – GarrisRyder Dec 19 '18 at 13:08
  • 1
    use stack views you will achieve what u want it will automatically adjust according to screen, give constrains to stack – junaid Dec 19 '18 at 13:12
  • Question is not clear. Are you trying to give the `programmatically constrain`? Still For the top `UIImageView` please embed all the image in the `stackView`. And for the `UIButton` you can use the `UICollectionView`. That's the easiest way I think. – Krunal Nagvadia Dec 19 '18 at 13:17

1 Answers1

0

I see you want margins and sizes of the buttons to be relative to screen size. I recommend you to set in Interface Builder only margins around the buttons for each size class. If the number of the buttons is fixed, probably this will be the easiest way to solve you problem.

Roman Aliyev
  • 224
  • 2
  • 7