千家信息网

ios中UICollectionView怎么用

发表于:2024-10-10 作者:千家信息网编辑
千家信息网最后更新 2024年10月10日,小编给大家分享一下ios中UICollectionView怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!- (voi
千家信息网最后更新 2024年10月10日ios中UICollectionView怎么用

小编给大家分享一下ios中UICollectionView怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

- (void)viewDidLoad {

[super viewDidLoad];

self.title = @"UICollectionView的基本使用";

self.view.backgroundColor = [UIColor whiteColor];

UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];

UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];

collectionView.delegate = self;

collectionView.dataSource = self;

[collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellID"];

[self.view addSubview:collectionView];

// Do any additional setup after loading the view.

}

#pragma mark UICollectionView-delegate and dataSource-UICollectionViewCell的总个数

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

return 100;

}

#pragma mark UICollectionView-delegate and dataSource 每个UICollectionViewCell

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

static NSString *cellID = @"cellID";

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];

if(cell == nil){

cell = [[UICollectionViewCell alloc] init];

}

cell.backgroundColor = [UIColor grayColor];

return cell;

}

#pragma mark -- UICollectionViewDelegate 设置每个 UICollectionView 的大小

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath

{

return CGSizeMake(CGRectGetWidth(self.view.bounds)/3-10, CGRectGetWidth(self.view.bounds)/3-10);

}

#pragma mark - CollectionView section 的个数

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

{

return 1;

}

#pragma mark-设置每个UICollectionView 的间距

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

return UIEdgeInsetsMake(0, 0, 0,0);

}

#pragma mark-设置每个UICollectionView 的纵向间距

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

return 10;

}

#pragma mark-设置每个UICollectionView 的横向间距

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{

return 10;

}

#pragma mark-UICollectionView的点击事件

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

NSLog(@"%@",@(indexPath.row).description);

}

以上是"ios中UICollectionView怎么用"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

篇文章 间距 个数 内容 不怎么 事件 大小 大部分 更多 横向 知识 纵向 行业 资讯 资讯频道 频道 参考 学习 帮助 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 网络安全技术探究 商丘软件开发税务筹划该怎么做 南京安卓应用软件开发多少钱 查看数据库引擎 网易邮箱大师苹果手机服务器端口 保利桥二破解版免谷歌服务器 河北大学网络安全活动 网络安全注入工具 软件开发公司如何提高利润率 网络安全法有修改吗 我国提出网络安全 吕梁政务软件开发价格 网络安全高中主题班会教案 文件元数据库 山西上门软件开发条件 ssr vue服务器渲染 网络安全的十大案例 广东省企业税控盘连接服务器地址 广州纷享网络技术有限公司 多媒体法制展厅软件开发 西城区网络营销软件开发反馈 学生管理系统要连接数据库 法正北京软件开发有限公司 宁波信息化网络技术参考价格 企业网络安全管理答辩 东莞erp软件开发哪家好 电脑端口进入服务器代码 用git管理阿里云服务器 浦东公安分局网络安全支队长 莱芜巨幕服务器
0