iOS 常用代码之 UICollectionView
记一下 不用每次都从0开始写,人生苦短 ,省点时间给自己 之前必须完成相关注册:
. cell
. 头部和尾部 [self.hotAndHistoryCollectionV registerNib:[UINib nibWithNibName:@"HotAndHistoryCell" bundle:nil] forCellWithReuseIdentifier:@"hotSearchCellID"];
[self.hotAndHistoryCollectionV registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headViewID"]; #pragma mark --- hot search collectionViewDelegate --- - (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
HotAndHistoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"hotSearchCellID" forIndexPath:indexPath];
//cell.backgroundColor = [UIColor redColor];
//cell.contentView.backgroundColor = [UIColor blackColor];
return cell;
} - (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return ;
} - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return ;
} -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
if ([kind isEqual:UICollectionElementKindSectionHeader]) {
//UIView *headView = [[UIView alloc]init];
UICollectionReusableView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"headViewID" forIndexPath:indexPath]; if (indexPath.section == ) {
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(,,,);
label.text = @"热门搜索";
label.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:];
label.textColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:];
[headView addSubview:label];
}
else {
UIView *view = [[UIView alloc] init];
view.frame = CGRectMake(,,self.view.frame.size.width,);
view.backgroundColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:];
[headView addSubview:view]; UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(,,,);
label.text = @"历史搜索";
label.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:];
label.textColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:];
[headView addSubview:label]; UIButton *trashBtn = [UIButton new];
trashBtn.frame = CGRectMake(headView.frame.size.width - - , , , );
[trashBtn setImage:[UIImage imageNamed:@"search_iconbtn_delete_default"] forState:UIControlStateNormal];
[headView addSubview:trashBtn];
}
return headView; }
return nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
if (section == ) {
return CGSizeMake(self.view.frame.size.width, );
}
else{
return CGSizeMake(self.view.frame.size.width, );
} } //定义每个UICollectionView 的大小
- ( CGSize )collectionView:( UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:( NSIndexPath *)indexPath {
return CGSizeMake((self.view.frame.size.width - * )/,);
}
//定义每个UICollectionView 的边距
- ( UIEdgeInsets )collectionView:( UICollectionView *)collectionView layout:( UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:( NSInteger )section {
return UIEdgeInsetsMake ( , , , );
}
////设置水平间距 (同一行的cell的左右间距)
//-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
// return 9;
//}
////垂直间距 (同一列cell上下间距)
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
// return 9;
//}
iOS 常用代码之 UICollectionView的更多相关文章
- IOS常用代码整理
常用代码整理: 12.判断邮箱格式是否正确的代码: //利用正则表达式验证 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRege ...
- iOS 常用代码块
1.判断邮箱格式是否正确的代码: // 利用正则表达式验证 -( BOOL )isValidateEmail:( NSString *)email { NSString *emailRegex ...
- iOS常用代码总结
1.读取图片NSString *path = [[NSBundle mainBundle] pathForResource"icon" ofType"png"] ...
- iOS开发 纯代码创建UICollectionView
转:http://jingyan.baidu.com/article/eb9f7b6d8a81a5869364e8a6.html iOS开发 纯代码创建UICollectionView 习惯了使用xi ...
- iOS常用技术
1.判断系统 #define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersi ...
- iOS常用的设计模式
iOS常用的设计模式有:单例模式.委托模式.观察者模式和MVC模式.下面分别简单介绍. 一:单例模式 我们常用的UIApplication.NSUserdefaults.NSNotificationC ...
- [iOS]一行代码集成空白页面占位图(基于runtime+MJRefresh思想)
2018年01月03日阅读 2472 [iOS]一行代码集成空白页面占位图(基于runtime+MJRefresh思想) LYEmptyView 此框架是本人在5,6个月前,公司启动新项目的时候, ...
- iOS 常用三方类库整理
iOS 常用三方类库整理 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https://gi ...
- iOS常用公共方法
iOS常用公共方法 字数2917 阅读3070 评论45 喜欢236 1. 获取磁盘总空间大小 //磁盘总空间 + (CGFloat)diskOfAllSizeMBytes{ CGFloat si ...
随机推荐
- apicloud地图、即时通讯、人脸识别登录、以及平时踩过得坑
apicloud技术浅谈 导语 apicloud 的学习也有一段时间了,这是我个人的一些经验,和踩过的坑,希望对大家能有一些帮助. apicloud的知识准备 apicloud 是一个用原生的思想搭建 ...
- c语言1博客作业12-学期总结
一.我学到的内容 二.收获总结 2.1我的收获 链接: c语言1博客作业01:https://www.cnblogs.com/dy-985211/p/11578914.html c语言1博客作业02: ...
- 将IDEA工程代码提交到Github
1.git安装配置 1.下载git https://git-scm.com/download/win 2.安装 傻瓜式安装即可,记住安装的目录 3.配置 2.配置git SSH 1.首先申请一个Git ...
- phpcms批量更新内容页只更新一点就返回问题
phpcms批量更新内容页只更新一点就返回问题 给caches目录增加写入权限
- BZOJ 3262(Treap+树状数组)
题面 传送门 分析 分三维考虑 对第一维,直接排序 对第二维和第三维,我们这样考虑 朴素的方法是建k棵Treap,第i棵Treap里存第二维值为k的第三维数值 每次查询一组(a,b,c),只要在1~b ...
- python——datetime模块
一.datetime模块介绍 (一).datetime模块中包含如下类: 类名 功能说明 date 日期对象,常用的属性有year, month, day time 时间对象 datetime 日期时 ...
- 【JMeter4.0】二、JMeter4.0安装与配置
二.安装配置JMeter jmeter是一个纯java工具,因此,JDK必不可少,现在最新版的jmeter是4.0,建议使用1.8及以上的JDK安装配置JDK,如没有,请见:[JMeter4.0]一. ...
- windos忘记密码登陆如何修复
一.简单的方法: 开机启动windows,进入欢迎界面后,会出现输入用户名密码提示框,这时候,同时按住Ctrl+Alt+Delete,会跳出一个账号窗口,输入用户名:administer,按回车即可. ...
- 20180223-logging模块
Python的logging模块提供了标准的日志接口,可以通过它存储各种格式的日志,logging的日志可以依次分为debug().info().warning().error().cirtical( ...
- PHP-不涉及第三个变量交换两个变量的值
不涉及第三个变量交换两个变量的值 方法1:使用加减法 <?php $a = 1; $b = 2; $a = $a+$b; $b = $a-$b; $a = $a-$b; printf(" ...