iOSManiac
iOSManiac

Reputation: 159

Aligning 3 buttons with dynamic contents in objective C using Autolayout

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.

Upvotes: 1

Views: 127

Answers (2)

Vishal Sonawane
Vishal Sonawane

Reputation: 2693

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.

enter image description here

Upvotes: 2

shallowThought
shallowThought

Reputation: 19602

Embed all UIBUttons 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.

Upvotes: 1

Related Questions