IOS 手写UICollectionView

//// ViewController.m// 手写UICollectionView//// Created by Bc_Ltf on 15/3/20.// Copyright (c) 2015年 Bc_Ltf. All rights reserved.//#import "ViewController.h"#define WEIGHT [UIScreen mainScreen].bounds.size.width#define HEIGHT [UIScreen mainScreen].bounds.size.height@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];[self setup];}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];}#pragma mark- setup-(void)setup{UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc ]init];UICollectionView *first=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0,WEIGHT ,HEIGHT) collectionViewLayout:flowLayout];/** 注册cell*///本文原创,转载请注明出处:[first registerClass:[UICollectionViewCell class]forCellWithReuseIdentifier:@"cell"];[self.view addSubview:first];first.dataSource=self;first.delegate=self;}#pragma mark- Source Delegate-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{return 3;}- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{return 2;}-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{static NSString *identify=@"cell";// UICollectionViewCell *cell=[[UICollectionViewCell alloc] init];UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];cell.contentView.backgroundColor=[UIColor whiteColor];return cell;}#pragma mark- FlowDelegate- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{return CGSizeMake(WEIGHT/3, WEIGHT/3);}-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{return WEIGHT/9;}- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;{return UIEdgeInsetsMake(WEIGHT/18, WEIGHT/9, WEIGHT/18, WEIGHT/9);}@end

本文原创,转载请注明出处:

,志在山顶的人,不会贪念山腰的风景。

IOS 手写UICollectionView

相关文章:

你感兴趣的文章:

标签云: