how to make horizontal scrolling menu in iOS

前端 未结 2 936
猫巷女王i
猫巷女王i 2021-02-03 13:48

I would like to make a menu which will have horizontal scrolling.

The menu contains total 16 categories. So I am planning to take 8 on first part and rest 8 on another p

2条回答
  •  臣服心动
    2021-02-03 14:16

    You can accomplish you're goal using a UIScrollView and your UIButton objects, it would involve setting each button's frame / layout properties depending on what iOS version you're targeting. (As in Eric's answer).

    However, if you're targeting iOS 6 and above, using a UICollectionView where your items/cells are the buttons, then you can get the horizontal scrolling "menu bar" for free. There are plenty of SO posts on this, but the main idea is to use a flow layout where the item size has a height such that there will only be one row of items (just make the item height the same as the collection view's height).

    EDIT:

    I should say, this might seem like overkill (and maybe it is), but you will end up with a much more flexible component in case requirements change in the future. It also doesn't result in much extra code and abstracts away tedious layout details.

提交回复
热议问题