UICollection布局
来源:互联网 发布:c语言 sleep 1 编辑:程序博客网 时间:2024/05/20 18:17
UICollectionView 是针对IOS6 以后才能使用的 控件,比起UITableView来说功能更强大,使用起来更方便!
使用UICollectionView最重要的一点就是加载设置UICollectionViewFlowLayout,一下是自己总结的使用UICollectionView的具体使用步骤:
一:创建 UICollectionView控件 并 registerClass 具体代如下:
SQCollectionView = [[UICollectionViewalloc]initWithFrame:CGRectMake(0,64,SCREEN_WIDTH,SCREEN_HEIGHT-64)collectionViewLayout:[[collectionViewFlowLayoutalloc]init]];
[SQCollectionViewregisterClass:[CollectionViewCellclass]forCellWithReuseIdentifier:@"cell"];
SQCollectionView.delegate =self;
SQCollectionView.dataSource =self;
SQCollectionView.contentOffset =CGPointMake(0,0);
SQCollectionView.backgroundColor=[UIColorclearColor];
[SQCollectionViewsetContentInset:UIEdgeInsetsMake(0,0,0,0)];
[self.viewaddSubview:SQCollectionView];
self.coverImageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,collectionview_cell_width,125)];
[self.coverImageView.layersetCornerRadius:5];
self.coverImageView.layer.masksToBounds = YES;
[self.contentViewaddSubview:self.coverImageView];
self.nameLabel = [[UILabelalloc]initWithFrame:CGRectMake(0,132,collectionview_cell_width,15)];
self.nameLabel.font = [UIFontsystemFontOfSize:15];
[self.contentViewaddSubview:self.nameLabel];
三:创建UICollectionViewFlowLayout 设置其布局,具体设置代码如下:
self = [superinit];
if (self) {
self.itemSize =CGSizeMake(ITEM_WIDTH,ITEM_HEIGHT);
//排列方向 (这里需要注意的是 可以设置横向滑动 对一些特定功能来说更方便处理)
self.scrollDirection =UICollectionViewScrollDirectionVertical;
self.sectionInset =UIEdgeInsetsMake(8,10,15,10);
//行间隔
self.minimumLineSpacing =15;
self.minimumInteritemSpacing =7;
}
returnself;
设置完这些之后 剩下就是 UICollectionViewDelegate 的一些代理方法了
#pragma mark - collectionViewDelegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return20;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return1;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
staticNSString * cellIndetifier =@"cell";
CollectionViewCell * cell = [collectionViewdequeueReusableCellWithReuseIdentifier:cellIndetifierforIndexPath:indexPath];
[cell loadCollectionUI:[NSStringstringWithFormat:@"第%ld个元素",(long)indexPath.row]];
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
}
- UICollection布局
- iOS ---UICollection
- iOS--UICollection
- UICollection全屏时错误
- UICollectionView
- UiAutomator UiCollection API
- UICollection using Swift
- UICollection using Swift
- Android UiAutomator UiCollection类
- uicollection卡动
- UiAutomator之UiCollection UiScrollable UiWatcher
- UiAutomator之UiCollection UiScrollable UiWatcher
- UICollection view or Tableview 使用
- swift 中UIColleCtion简单使用
- 七、UiCollection API 详细介绍
- UiAutomator(4)--UiCollection API
- UICollection代理方法didSelectIte…
- uiautomator中UiCollection学习笔记(4)
- ossec的配置及批量安装
- CATALINA_HOME和CATALINA_BASE
- C语言基础——指针
- CodeTyphon32中自带例子源码:5行代码取得所有进程列表。
- 命令行退出python方法
- UICollection布局
- 深入剖析scala的App特质
- xp下搭建FTP服务器过程中遇到的问题
- eclipse在Linux下的安装配置maven
- Hadoop启动namenode失败,端口号冲突问题解决
- C# linq
- 如何实现营销型网站推广的终极目标?
- three.js 画网格
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout