make view controller scrollable with collection view

被刻印的时光 ゝ 提交于 2019-12-25 08:46:28

问题


I need to create a view controller like this or like user instagram's profile

not exactly same, I just want to add label and buttons and collection view, but I want all of this in scroll viewController
I think I can't do that from storyboard, so how I can make a view controller scrollable programmatically?
and then I want to add the label and buttons inside the scroll , I can do that programmatically , but how I can add collection programmatically inside it?


回答1:


One of the possible solutions is to make the whole container a "UICollectionView" -or "UITableView", depends on what exactly you want to build-, and then, create a custom cell for each area depending on what do you want to display in it.

It might sounds a little bit strange in the beginning, but you will notice that it is a great technique to handle scrolling in your scene, including some of extra nice features, such as:

  • auto scroll content resizing for "UIKeyboardWillShowNotification" and "UIKeyboardWillHideNotification" events.
  • the ease of showing and hiding sections from the UI (actually they are cells!).

UPDATED: For example:

You can make the first part (red rectangle) as a UICollectionReusableView and customize it by adding your images and button in it, second part (blue square) as a UICollectionViewCell and so on...

This is the general idea of what how you can do it.



来源:https://stackoverflow.com/questions/39714212/make-view-controller-scrollable-with-collection-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!