Header and footer are additions to the layout of the view flow. By default, these views are disabled in the flow layout. However, there are several things you can do to configure header and footer views:
First, drag CollectionView, and related settings
In storyboard, select Collection View in the Collection view controller. In Attributes Inspector, select section Header and section Footer, and once selected you will see collection Showing his header and his footer.b7a4a035-9845-47e3-b2ef-0e392e884841.
The default is null between header and footer, and we use storyboard to design the view. The head is specifically used to display a section of the caption, while the bottom view displays only static banner pictures.
Ii. implementation of Viewforsupplementaryelementofkind method
If you try to run the application, you may not see headers and footer, because we haven't implemented the "Viewforsupplementaryelementofkind:" method.
The code is as follows:
-(Uicollectionreusableview *) CollectionView: (Uicollectionview *) CollectionView Viewforsupplementaryelementofkind :(NSString *) kind Atindexpath: (Nsindexpath *) Indexpath
{
Uicollectionreusableview *reusableview = nil;
if (kind = = Uicollectionelementkindsectionheader) {
Uicollectionreusableview *headerview = [CollectionView dequeuereusablesupplementaryviewofkind: Uicollectionelementkindsectionheader withreuseidentifier:@" headerview" Forindexpath:indexpath];
Reusableview = Headerview;
}
if (kind = = Uicollectionelementkindsectionfooter) {
Uicollectionreusableview *footerview = [CollectionView dequeueresuablesupplementaryviewofkind: Uicollectionelementkindsectionfooter withreuseidentifier:@" footerview" Forindexpath:indexpath];
Reusableview = Footerview;
}
return reusableview;
}
The above code tells it that the header/footer view should use Collect view in each section. We first determine that the collection view requires header or footer view. This can be done by using a variable. For the head, we column header view (using the Dequeuereusablesupplementaryviewofkind: method) and set the appropriate title and image. As you can from the two if code between, we use our previous assignment to get the Header/footer view identifier.