I have 3 buttons one below the other.The requirement is , all should be centrally aligned.Also the dynamic contents should fit in these 3 buttons.Please help me with this issue. I have only a vague understanding about content hugging, compression resistance and intrinsic content size.Thank you very much in advance.
Asked
Active
Viewed 122 times
1
-
1The simplest solution would be to use stack view for buttons and set that stack view in centre. for dynamic content set stackviews heightConstraint gretaer than equal relation. – Vishal Sonawane Jan 05 '17 at 11:22
-
@Vishal:Hi Vishal, Thank you for your comment.Could you please tell me about the implementation of the same, below iOS 9? – iOSManiac Jan 09 '17 at 07:56
-
It will be same. Just use UIView Instead of stackView. Apply same height and same width constraint to all buttons and deal with height constraint of the container UIView. – Vishal Sonawane Jan 09 '17 at 08:23
2 Answers
2
For iOS 9
and later:
Use UIStackView
to embed all your buttons
and set that stack view
in centre of the view
. For dynamic content, set stackView's
heightConstraint
greater than equal relation
(>=).
For iOS 8
and earlier:
Just use UIView
Instead of UIStackView
. Rest of the things will be same.

Vishal Sonawane
- 2,637
- 2
- 16
- 21
1
Embed all UIBUtton
s within a UIStackView
and set the stackViews properties to you needs.
To get the idea, see this answer.
Note: UIStackView
is only available under iOS >= 9.

Community
- 1
- 1

shallowThought
- 19,212
- 9
- 65
- 112
-
1Depending on the iOS he needs to support. Stackviews are only available on iOS 9+ if that is not a problem then yes the easiest would be using stackview. – Pancho Jan 05 '17 at 13:08
-
-
What can be done if the version is < iOS 9? Thank you very much for your answer and comments. – iOSManiac Jan 05 '17 at 13:22
-