collectionview使用
来源:互联网 发布:人工智能 百度网盘 编辑:程序博客网 时间:2024/06/04 21:38
创建UICollectionViewFlowLayout 对象来设置相关的布局,包括itemSize,headerReferenceSize,sectionInset。设置对应的布局大小,相关的和顶部之间的间距等。
UICollectionView创建对应的view并且定义对应的大小,设置代理方法和数据源对象。
-(void)loadCollectionView{ UICollectionViewFlowLayout * collectionViewFlow = [[UICollectionViewFlowLayout alloc]init]; UICollectionView *collectView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, ScreenHeight, CGRectGetWidth(_homeScrollView.frame), 2000)collectionViewLayout:collectionViewFlow]; collectView.dataSource = self; collectView.delegate = self; collectView.backgroundColor = [UIColor blueColor]; [collectView registerClass:[CSHomeCollectionViewCell class] forCellWithReuseIdentifier:@"collectionCell"]; collectionViewFlow.itemSize = CGSizeMake(93, 120); collectionViewFlow.sectionInset = UIEdgeInsetsMake(40, 0, 0, 0); collectionViewFlow.scrollDirection = UICollectionViewScrollDirectionVertical; [_homeScrollView addSubview:collectView];}//datasource,delegate-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return 20;}-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ CSHomeCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath]; cell.topImage.image = [UIImage imageNamed:@"cludy_bg"]; return cell;}
从而来实现对应的方法,其中自定义的cell类
-(instancetype)initWithFrame:(CGRect)frame{ self =[super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor grayColor]; self.topImage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, MYSIZE.width-10, MYSIZE.height*0.6)]; [self addSubview:_topImage]; self.designer = [[UILabel alloc]initWithFrame:CGRectMake(5, CGRectGetHeight(self.topImage.frame), CGRectGetWidth(self.frame), 20)]; self.designer.text = @"hello"; [self addSubview:_designer]; // self.goodBtn = [UIButton alloc]initWithFrame:CGRectMake(0, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>) } return self;}
当定义的时候,自动调用initwithframe函数来初始化
0 0
- CollectionView 使用
- collectionview使用
- iOS collectionView使用
- collectionview flowLayout使用
- CollectionView的使用
- iOS CollectionView简单使用
- collectionView的使用iOS
- iOS collectionView的使用
- collectionView使用总结
- collectionView纯代码使用
- CollectionView使用入门
- storyboard使用collectionview
- 关于iOS10使用collectionview
- CollectionView Header的使用
- CollectionView
- collectionView
- collectionView
- collectionView
- 关于block的一些理解
- Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptabl
- loadView、viewDidLoad、initWithCoder、initWithNibName、awakeFromNib的用法
- Java Socket网络编程的经典例子(转)
- 什么是一个对象?
- collectionview使用
- 关于delegate(代理)总结
- ios启动载入启动图片
- ios中图片拉伸用法
- 代码搭建记事本框架(二)
- 代码搭建记事本框架(一)
- (转)RVA-相对虚拟地址解释
- BigInger isProbablePrime
- 理解奈奎斯特定理和香农定理