UICollectionView
2015-10-09 14:15
393 查看
UICollectionView跟安卓中的RecycleView很像,使用也很像,安卓通过adapter,ios通过UICollectionViewDelegate,UICollectionViewDataSource协议
具体使用方式:
1.新建ios工程
2.ViewController中实现相关协议
3.实现ViewController
效果图
具体使用方式:
1.新建ios工程
2.ViewController中实现相关协议
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout> @end
3.实现ViewController
// // ViewController.m // uicollectionview // // Created by Young on 15/10/9. // Copyright (c) 2015年 Young. All rights reserved. // #import "ViewController.h" @interface ViewController () @end static NSString* cid=@"cid"; @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //采用流布局,若想实现其他功能,比如按下抬起效果等可以实现UICollectionViewDelegateFlowLayout中相关协议 UICollectionView* collec=[[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:[[UICollectionViewFlowLayout alloc]init]]; [collec registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:cid]; //设置自身为数据源 collec.dataSource=self; collec.delegate=self; [self.view addSubview:collec]; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ return CGSizeMake(120, 120); } //待显示的数量 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return 50; } // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: //UICollectionView中每一个控件是一个UICollectionViewCell,可以通过继承UICollectionViewCell来自定义布局 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ UICollectionViewCell* cell=[collectionView dequeueReusableCellWithReuseIdentifier:cid forIndexPath:indexPath]; cell.backgroundColor=[UIColor yellowColor]; return cell; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
效果图
相关文章推荐
- 16进制颜色转UIColor
- iOS 编译失败,但是没有错误提示(ios build failed ,but without errors)
- Volley框架关于RequestQueue的心得
- 响应式web设计之CSS3 Media Queries
- 在非GUI程序中调用wxThread出现segmentation fault
- 不同情况下request.getContextPath()值的区别
- uitabBar上面的各定义选中时的图片颜色。不要渲染
- Arduino IDE的#ifdef bug
- 第二十九篇:使用SOUI的SMCListView控件
- [Android UI开发] viewpager fragment 切换时oncreateview调用多次问题
- iOS UILabel显示HTML文本
- 解决Django 提交表单时403错误:CSRF verification failed. Request
- UIView的layoutSubviews和drawRect方法何时调用
- 探究UIImagePickerController
- 循环队列_queue
- java中List、Map、Set、Collection、Stack、Queue等的使用
- Fourier Transform Intro - Oscillation frequency vs Angular frequency Expression
- poj 3498 March of the Penguins(最大流+拆点)
- Leetcode89: Unique Paths
- StringBuilder、StringBuffer和String三者的联系和区别