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 ...
随机推荐
- Sending form data
https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data This arti ...
- MySQL分组聚合group_concat + substr_index
场景:给予一张商品售卖表,表中数据为商品的售卖记录,假设表中数据是定时脚本插入的,每个时间段的商品售卖数量不同,根据此表找各个商品的最多售卖数量的数据. 1.数据表 CREATE TABLE `goo ...
- npm install 安装过程卡住不动
修改 npm 的安装目录下的 npmrc文件 增加一条 registry=http://registry.cnpmjs.org $ npm config set registry http://reg ...
- SEC5 - MySQL 查询语句--------------进阶1:基础查询
# 进阶1:基础查询 /* 语法: select 查询列表 from 表名: 特点: 1.查询列表可以是:表中的字段.常量值.表达式.表达式.函数 2.查询的结果是一个虚拟的表格 如何执行:执行谁,请 ...
- BERT实战——基于Keras
1.keras_bert 和 kert4keras keras_bert 是 CyberZHG 大佬封装好了Keras版的Bert,可以直接调用官方发布的预训练权重. github:https://g ...
- System的两常用个静态方法
package cn.learn; /* System类在java.lang.System,和操作系统有关 1.currentTimeMillis直接调用,是一个返回为long型的静态方法 常用来计算 ...
- from、includes、indexOf
from.includes.indexOf:https://blog.csdn.net/j59580/article/details/53897630?utm_source=blogxgwz1 语法 ...
- 微信、QQ、新浪微博等第三方登录,你想知道的都在这了(上) 微信、QQ、新浪微博等第三方登录,你想知道的都在这了(下)
微信.QQ.新浪微博等第三方登录,你想知道的都在这了(上):https://www.jianshu.com/p/133d84042483 微信.QQ.新浪微博等第三方登录,你想知道的都在这了(下):h ...
- CSS动画划入划出酷炫
HTML插入 <!DOCTYPE html> <html class="no-js iarouse"> <head> <meta char ...
- GnuTLS 3.3.3 remote memory corruption(CVE-2014-3466)
Buffer overflow in the read_server_hello function in lib/gnutls_handshake.c in GnuTLS before 3.1.25, ...