记一下 不用每次都从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的更多相关文章

  1. IOS常用代码整理

    常用代码整理: 12.判断邮箱格式是否正确的代码: //利用正则表达式验证 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRege ...

  2. iOS 常用代码块

    1.判断邮箱格式是否正确的代码: // 利用正则表达式验证 -( BOOL )isValidateEmail:( NSString  *)email {   NSString  *emailRegex ...

  3. iOS常用代码总结

    1.读取图片NSString *path = [[NSBundle mainBundle] pathForResource"icon" ofType"png"] ...

  4. iOS开发 纯代码创建UICollectionView

    转:http://jingyan.baidu.com/article/eb9f7b6d8a81a5869364e8a6.html iOS开发 纯代码创建UICollectionView 习惯了使用xi ...

  5. iOS常用技术

    1.判断系统 #define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersi ...

  6. iOS常用的设计模式

    iOS常用的设计模式有:单例模式.委托模式.观察者模式和MVC模式.下面分别简单介绍. 一:单例模式 我们常用的UIApplication.NSUserdefaults.NSNotificationC ...

  7. [iOS]一行代码集成空白页面占位图(基于runtime+MJRefresh思想)

    2018年01月03日阅读 2472   [iOS]一行代码集成空白页面占位图(基于runtime+MJRefresh思想) LYEmptyView 此框架是本人在5,6个月前,公司启动新项目的时候, ...

  8. iOS 常用三方类库整理

    iOS 常用三方类库整理 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https://gi ...

  9. iOS常用公共方法

      iOS常用公共方法 字数2917 阅读3070 评论45 喜欢236 1. 获取磁盘总空间大小 //磁盘总空间 + (CGFloat)diskOfAllSizeMBytes{ CGFloat si ...

随机推荐

  1. mysql_DML_select_子查询

    -------------------------------------------------------------------子查询---------------------   --1.子查 ...

  2. Jenkins使用五:创建部署任务

    创建部署任务 选择运行节点 选择使用shell # 如果是持续进程,这里最好加一个kill进程的命令 判断如果/root/production目录存在,就删除if [ -d /root/product ...

  3. EF框架之——Code First以及踩过的这些“坑”

    传送门 Code First使用步骤 Code First报错和解决办法 以前在上海做了一段时间的Asp.net,基本用的都是.net自带的EF框架连接数据库,不过都是用的Model First,最近 ...

  4. 28. Jmeter函数

    Jmeter函数传送门 软件测试汪简书地址 软件测试汪博客地址 欢迎关注微信公众号:软件测试汪.软件测试交流群:809111560 转载请注意出处,谢谢合作

  5. upc组队赛16 Winner Winner【位运算】

    Winner Winner 题目链接 题目描述 The FZU Code Carnival is a programming competetion hosted by the ACM-ICPC Tr ...

  6. android button click事件

    package a.a; import android.app.Activity;import android.os.Bundle;import android.view.View;import an ...

  7. 【Jmeter】利用Jmeter+ant+Jenkins 搭建 接口&性能测试 持续集成平台

    https://www.jianshu.com/p/6ab73a95d53e https://yq.aliyun.com/articles/664329

  8. 复制书稿 (dp+贪心)

    [题目描述] 现在要把m本有顺序的书分给k个人复制(抄写),每一个人的抄写速度都一样,一本书不允许给两个(或以上)的人抄写,分给每一个人的书,必须是连续的,比如不能把第一.第三和第四本书给同一个人抄写 ...

  9. 【转】 关于form与表单提交操作的一切

    参考一:http://caibaojian.com/form.html 参考二:https://blog.csdn.net/weixin_42301628/article/details/867156 ...

  10. spring的@Value注解使用

    https://blog.csdn.net/woheniccc/article/details/79804600 昨天看到了springMVC的controller中的属性使用了@value注解,并且 ...