IOS Uicollectionview Handwriting Code implementation steps
//
ViewController.h
CollectionView Handwriting Code
//
Created by yangxiuying on 14/11/28.
Copyright (c) 2014 lanjiying. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface viewcontroller:uiviewcontroller<uicollectionviewdatasource,uicollectionviewdelegate>
{
NSString * identifier;
}
//
Viewcontroller.m
CollectionView Handwriting Code
//
Created by yangxiuying on 14/11/28.
Copyright (c) 2014 lanjiying. All rights reserved.
//
#import "ViewController.h"
@interface Viewcontroller ()
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Additional setup after loading the view, typically from a nib.
identifier = @ "cell";
Initialize layout
Uicollectionviewflowlayout * FlowLayout =[[uicollectionviewflowlayout alloc] init];
[FlowLayout setscrolldirection:uicollectionviewscrolldirectionvertical];
Uiedgeinsets top = {15,10,15,5};
[FlowLayout Setsectioninset:top];
Uicollectionview * CollectionView =[[uicollectionview alloc] Initwithframe:cgrectmake (0, 30, 320, 480) Collectionviewlayout:flowlayout];
Registering cells
[CollectionView Registerclass:[uicollectionviewcell Class]forcellwithreuseidentifier:identifier];
Set up Proxy
Collectionview.delegate = self;
Collectionview.datasource = self;
[Self.view Addsubview:collectionview];
}
#pragma mark-collectionview delegate
Set partition
-(Nsinteger) Numberofsectionsincollectionview: (Uicollectionview *) CollectionView
{
return 1;
}
Set the Size box for an element
-(Uiedgeinsets) CollectionView: (Uicollectionview *) CollectionView layout: (Uicollectionviewlayout *) Collectionviewlayout Insetforsectionatindex: (nsinteger) Section
{
Uiedgeinsets top = {30,15,30,15};
return top;
}
Number of elements on each partition
-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (NSInteger) Section
{
return 24;
}
Set element content
-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) Indexpath
{
Uicollectionviewcell * Cell =[collectionview dequeuereusablecellwithreuseidentifier:identifier ForIndexPath: Indexpath];
[Cell SizeToFit];
Cell.backgroundcolor =[uicolor Greencolor];
return cell;
}
Set cell width
Set element size
-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout *) collectionviewlayout Sizeforitematindexpath: (Nsindexpath *) indexpath{
Return Cgsizemake (140,160);
}
IOS Uicollectionview Handwriting Code implementation steps