IOS Uicollectionview Handwriting Code implementation steps

Source: Internet
Author: User
Tags uikit

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

Related Article

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.