How to use AutoLayout to position UIButtons in horizontal lines?
Posted
by
thomers
on Stack Overflow
See other posts from Stack Overflow
or by thomers
Published on 2013-11-06T09:50:20Z
Indexed on
2013/11/06
9:52 UTC
Read the original article
Hit count: 173
I need to create a couple of UIButtons programmatically in my app (iOS 6.0 and above).
Each button should have the optimal width to display button label text (of various lenghts).
I want to display the buttons in a "wrap around" style: Starting from the left edge, each button should be positioned next to each other horizontally (in a defined order), and if a button does not fit in the current "line", it should start a new line on the left edge below the previous line.
I could manually calculate the frame of each button in my code, but should I use AutoLayout (with programmatically creates NSLayoutConstraints) instead? How exactly would I need to set it up?
© Stack Overflow or respective owner