21st Lecture. Uicollectionview (collection View) and waterfall flow effect, Notification Center (nsnotificationcenter).

Source: Internet
Author: User
Tags notification center

I. Collection view (Uicollectionview)

1. Concept of the collection view

2. How to create

3. Layout of the collection view Uicollectionviewflowlayout

4. Custom cell and Layout protocol Uicollectionviewdelegateflowlayout

The cell is typically customized when used, and proxies are used in the layout.

Uicollectionview's basic Usage example code analysis:

#import "ViewController.h"#import "CollectionReusableView.h"@interfaceViewcontroller () <UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>@property (nonatomic,strong) Uicollectionview*CollectionView;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload];    [Self loadcollectionview]; //Registration Method Creation Uicollectionview[Self.collectionview Registerclass:[uicollectionviewcellclass] Forcellwithreuseidentifier:@"CELL"]; }-(void) loadcollectionview{//Layout class controls the style of each itemUicollectionviewflowlayout *flowlayout =[[Uicollectionviewflowlayout alloc] init]; Flowlayout.itemsize= Cgsizemake ( -, -); //change the size of the upper and lower rows (default is ten)Flowlayout.minimumlinespacing = -; //set the middle size of the two item (default is ten)Flowlayout.minimuminteritemspacing =37.5; //Control Example screen distance up left lower right//flowlayout.sectioninset = uiedgeinsetsmake (100, 100, 100, 0); //Transverse slide//flowlayout.scrolldirection = uicollectionviewscrolldirectionhorizontal;Self.collectionview=[[Uicollectionview alloc]initwithframe:self.view.frame collectionviewlayout:flowlayout]; //Background ColorSelf.collectionView.backgroundColor =[Uicolor Whitecolor]; Self.collectionview.Delegate=Self ; Self.collectionView.dataSource=Self ;        [Self.view AddSubview:self.collectionView]; //registering Haeder and Footer methods//Register a Headerview for CollectionView[Self.collectionview Registerclass:[collectionreusableviewclass] Forsupplementaryviewofkind:uicollectionelementkindsectionheader Withreuseidentifier:@"Header"]; //Register a Footerview for CollectionView[Self.collectionview Registerclass:[uicollectionreusableviewclass] Forsupplementaryviewofkind:uicollectionelementkindsectionfooter Withreuseidentifier:@"Footer"]; }//return header and footer settings header and footer-(Uicollectionreusableview *) CollectionView: (Uicollectionview *) CollectionView Viewforsupplementaryelementofkind :(NSString *) kind Atindexpath: (Nsindexpath *) indexpath{if([Kind Isequaltostring:uicollectionelementkindsectionheader]) {Uicollectionreusableview*header = [CollectionView dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionheader Withreuseidentifier:@"Header"Forindexpath:indexpath]; returnheader; }  Else{Uicollectionreusableview*footer = [CollectionView dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionfooter Withreuseidentifier:@"Footer"Forindexpath:indexpath]; returnfooter; }   }//sets the size of the footer and header of the CollectionView-------the Uicollectionviewdelegateflowlayout proxy method----------//set the size of the CollectionView footer-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (Uicollectionviewlayout *) collectionviewlayout referencesizeforfooterinsection: (nsinteger) section{returnCgsizemake ( -, -);}//set the header size of the CollectionView-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (Uicollectionviewlayout *) collectionviewlayout referencesizeforheaderinsection: (nsinteger) section{returnCgsizemake ( -, -);}//the two proxy methods that you need to implement when you create a uicollectionview------------------------------------(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (nsinteger) section{return  -;}-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) indexpath{//Uicollectionviewcell does not carry the control itself, it is a blank//so, in the project, we usually customize a UicollectionviewcellUicollectionviewcell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:@"CELL"Forindexpath:indexpath]; //Set Background colorCell.backgroundcolor =[Uicolor Redcolor]; returncell;}


Two. Notification Center (Nsnotificationcenter)

21st Lecture. Uicollectionview (collection View) and waterfall flow effect, Notification Center (nsnotificationcenter).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.