In the previous blog, "spy on iOS development Uicollectionviewcontroller (iii)--use Uicollectionview to customize waterfall flow ", customize the number of columns in the waterfall stream, the cell margin, The maximum and minimum height of the cell is written dead in our layout file, in other words, it is not configurable. In order to gradually, easy-to-go, the previous blog so write. However, that is too rigid, originally used more flexible custom layout, if its configuration parameters to write dead, it is equivalent to the beast in the cage, and then the great not white pull pretty.
In today's blog we're going to go on to the demo in the previous blog so that the properties of its custom layout are configurable in the Uicollectionview that uses it. Of course, only four layout parameters are extracted from the demo to be introduced in this article, regardless of adding a delegate, the idea is the same. We put the dead content of the previous blog, through the layout agent to provide parameter configuration, so much more flexible. Okay, brackish, get into the subject of our day.
I. Evolution of the operating effect
As the demo version of the 2.0 operation effect, and compared with the previous function is really powerful. Because he is configurable, the style of the waterfall flow is determined based on the parameters entered by the user. Of course the demo is determined by the user input parameters, if you use the custom waterfall flow in the code, you need to configure the waterfall flow parameters according to your actual situation, to create your own waterfall stream. Although many of the internet to achieve waterfall stream blog and code, but like today can be configured waterfall flow should be not much, at least I have not seen, so I wrote a, open source, to share with you for a moment.
Second, custom waterfall flow usage mode
The use of this custom waterfall flow layout and the system's own uicollectionviewdelegateflowlayout usage have always been to customize layout parameters through the layout agent. Uicollectionviewdelegateflowlayout's content is detailed in theiOS development Uicollectionviewcontroller (ii)--detailed CollectionView various callbacks the contents of the Uicollectionviewdelegateflowlayout agent introduction.
If you want to use this layout file, you need to specify the layout file for our Uicollectionview, in this blog in the demo is in storyboard in the custom layout file specified, you can also be specified by the code, again do not do too much to repeat. After you specify the custom layout, you need to do the following things:
1. Assigning proxy methods to layouts
First get the layout collectionviewlayout for Uicollectionview and set it customecollectionviewlayoutdelegate Agent can, the code is as follows:
1 _customelayout = (Customecollectionviewlayout *) self.collectionviewlayout; 2 3 _customelayout.layoutdelegate = self;
2. Implementing the methods in Customecollectionviewlayoutdelegate
To set the layout properties by implementing the Proxy method in the custom layout in Uicollectionview's use controller, we have four methods that must be implemented. You can use these methods to set the cell's number of columns, the cell's margin, the cell's minimum height, and the cell's maximum height, as follows:
#pragmaMark <customecollectionviewlayoutdelegate>-(Nsinteger) Numberofcolumnwithcollectionview: (UICollectionView *) CollectionView Collectionviewlayout: ( Customecollectionviewlayout*) collectionviewlayout{return_cellcolumn;}-(CGFloat) Marginofcellwithcollectionview: (Uicollectionview *) CollectionView collectionviewlayout: ( Customecollectionviewlayout *) collectionviewlayout{return_cellmargin;}-(CGFloat) Minheightofcellwithcollectionview: (Uicollectionview *) CollectionView collectionviewlayout: ( Customecollectionviewlayout *) collectionviewlayout{return_cellminheight;}-(CGFloat) Maxheightofcellwithcollectionview: (Uicollectionview *) CollectionView collectionviewlayout: ( Customecollectionviewlayout *) collectionviewlayout{return_cellmaxheight;}
3. You can modify the properties of the custom layout by using the delegate method above, you can configure the parameters via a configuration page. After configuration, do CollectionView refresh, these in this blog do not repeat, please see the blog below the GitHub share address.
At this point, our custom waterfall flow is relatively complete, but there are also great improvements to the control. A small partner of interest can add your own stuff on this basis.
The GitHub share address in this blog post is:https://github.com/lizelu/CustomWaterfallFlow
iOS Development Spy Uicollectionviewcontroller (iv)--a powerful custom waterfall stream