UICollectionView Demo
来源:互联网 发布:阿里云域名怎么备案 编辑:程序博客网 时间:2024/05/21 17:33
闲来无事….写个UICollectionView Demo
//// ViewController.m// CollectionViewDemo//// Created by 赵伟争 on 2016/11/3.// Copyright © 2016年 zwz. All rights reserved.//#import "ViewController.h"@interface ViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>{ UICollectionViewFlowLayout *_customLayout; UICollectionView *_collectionView; BOOL isLogin; //YES: 登录, NO: 不是}@endstatic NSString *cellIdentifier = @"CELL";static NSString *headerIdentifier = @"header";static NSString *footIdentifier = @"foot";@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; isLogin = YES; //判断是否登录,手动设置, 或者登录后设置, 刷新整个CollectionView UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; //滚动方向 layout.scrollDirection = UICollectionViewScrollDirectionVertical; UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout]; collectionView.backgroundColor = [UIColor whiteColor]; collectionView.dataSource = self; collectionView.delegate = self; //UICollectionViewCell 可以自定义 [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:cellIdentifier]; //[collectionView registerClass:[ChoosePictureHeader class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier]; //[collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:footIdentifier]; [self.view addSubview:collectionView]; // Do any additional setup after loading the view, typically from a nib.}#pragma mark - UICollectionView数据源// 返回有多少个cell- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ if (section == 0) { if (isLogin) { return 4; } else { return 8; } } else { return 8; } // return 30;}- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView;{ if (isLogin) { return 2; } else { return 1; }}// 返回每个cell长什么样子- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ //可以自定义UICollectionViewCell UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; cell.backgroundColor = [UIColor redColor]; return cell;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}//设置item的大小- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGFloat width = [UIScreen mainScreen].bounds.size.width; if (indexPath.section == 0) { if (isLogin) { CGFloat oneSectionWidth = width/2; return CGSizeMake(oneSectionWidth-1.5, oneSectionWidth/2); } else { CGFloat oneSectionWidth = width/4; return CGSizeMake(oneSectionWidth-1.5, oneSectionWidth-1.2); } } else { CGFloat oneSectionWidth = width/4; return CGSizeMake(oneSectionWidth-1.5, oneSectionWidth-1.2); }}//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(15, 1, 5, 1);}//最小行间距- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 1.0f;}//item之间的最小距离- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 1.0f;}@end
0 0
- UICollectionView Demo
- UICollectionView的使用【附demo】
- UICollectionView的使用方法及demo
- UICollectionView自定义cell详解+demo
- UICollectionView的使用方法及demo
- iOS8 UICollectionView横向滑动demo
- 利用UICollectionView实现"新特性"功能demo
- UICollectionView
- UICollectionView
- UICollectionView
- UICollectionView
- UICollectionView
- UICollectionView
- UICollectionView
- UICollectionView
- UICollectionView
- UICollectionView
- UICollectionView
- 生成csv格式文件并导出至页面的前后台实现
- CSS学习笔记-块状元素-行间元素
- python下结巴分词(jieba)学习笔记
- NVIDIA DIGITS 5.1-dev学习笔记之安装过程记录:Windows10 x64位系统 、 MicroSoft Caffe Master、CUDA 8.0 、Python 2.7
- Android Service演义
- UICollectionView Demo
- 【demo记录】极光推送(android app访问服务器,服务器推送信息到新app)
- React-Native在APP调用浏览器或其他系统应用(Linking的使用)
- 利用按位异或运算符实现矩阵转置
- framework不兼容报错
- Taxi
- JVM -verbose参数详解(转)
- Java菜鸟面试突破系列之Java基础方面(一)
- eclipse报:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from