make view controller scrollable with collection vi

2019-09-11 12:16发布

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

enter image description here

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条回答
唯我独甜
2楼-- · 2019-09-11 12:57

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:

enter image description here

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.

查看更多
登录 后发表回答