float:left in objective-c

后端 未结 3 2056
执念已碎
执念已碎 2021-02-14 18:54

I\'m trying to make a bunch of buttons behave somewhat like float:left in CSS. So whenever the view changes size, on orientation change for example, the buttons should adjust so

3条回答
  •  野的像风
    2021-02-14 19:42

    If you had to implement this manually (by overriding layoutSubviews), I think the algorithm would be something like this:

    1. Start with X = 0, Y = 0 (assuming flipped coordinates)
    2. For each button:
      1. If (X + button width) > container width, set X = 0, increase Y
      2. Place button at (X, Y)
      3. Increase X by button's width

提交回复
热议问题