iOS UI 18 uicollectionview和自定义cell
来源:互联网 发布:mac os10.8.5升级10.9 编辑:程序博客网 时间:2024/05/16 10:24
//
// RootViewController.m
// Ui - 19 _ UICollectionView
//
// Created by dllo on 15/12/3.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import "RootViewController.h"
#import "CustomCollectionViewCell.h"
@interface RootViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@end
@implementation RootViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.view.backgroundColor = [UIColorwhiteColor];
//uicollectviewLayout 是一个抽象类,我们一般使用他的子类UICollectionViewFlowLayout
UICollectionViewFlowLayout *flowl = [[[UICollectionViewFlowLayoutalloc]init]autorelease];
//行间距
//注意:1,系统会尽可能靠近此参数,并保证不会小于
//垂直与滑动方向即为行!
flowl.minimumLineSpacing = 50;
//列间距
flowl.minimumInteritemSpacing = 50;
//单元大小
flowl.itemSize = CGSizeMake(100, 100);
//区头间据
flowl.headerReferenceSize =CGSizeMake(50, 50);
//区脚间距
flowl.footerReferenceSize =CGSizeMake(100, 100);
//与屏幕四周的间距
flowl.sectionInset = UIEdgeInsetsMake(10, 30, 10, 30);
//滚动方向
flowl.scrollDirection =UICollectionViewScrollDirectionHorizontal;
UICollectionView *collectionV = [[UICollectionViewalloc]initWithFrame:self.view.framecollectionViewLayout:flowl];
collectionV.backgroundColor = [UIColorpurpleColor];
collectionV.delegate = self;
collectionV.dataSource = self;
[self.viewaddSubview:collectionV];
[collectionV release];
//注册自定义cell
[collectionV registerClass:[CustomCollectionViewCellclass] forCellWithReuseIdentifier:@"cell"];
// Do any additional setup after loading the view.
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 100;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCollectionViewCell *cell = [collectionViewdequeueReusableCellWithReuseIdentifier:@"cell"forIndexPath:indexPath];
cell.label1.text =[NSStringstringWithFormat:@"%ld",indexPath.row];
return cell;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 3;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"点击%ld", indexPath.row);
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// CustomCollectionViewCell.h
// Ui - 19 _ UICollectionView
//
// Created by dllo on 15/12/3.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CustomCollectionViewCell : UICollectionViewCell
@property (nonatomic,retain)UILabel *label1;
@end
//
// CustomCollectionViewCell.m
// Ui - 19 _ UICollectionView
//
// Created by dllo on 15/12/3.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import "CustomCollectionViewCell.h"
@implementation CustomCollectionViewCell
- (void)dealloc
{
[_label1 release];
[super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
[self create];
}
return self;
}
- (void)create
{
self.backgroundColor = [UIColorredColor];
self.label1 = [[UILabelalloc]initWithFrame:CGRectMake(0,0 , 30, 30)];
[self.contentViewaddSubview:self.label1];
self.label1.backgroundColor = [UIColorwhiteColor];
[self.label1release];
}
@end
- iOS UI 18 uicollectionview和自定义cell
- iOS开发:xib之UICollectionView自定义cell
- swift UICollectionView 代码创建 和自定义Cell
- iOS UICollectionView 和 UITableView cell更新 详解
- iOS UI 08 uitableview 自定义cell
- UICollectionView 详解及自定义cell
- UICollectionView自定义cell详解+demo
- UICollectionView使用Xib自定义cell
- ios UICollectionView的cell重叠
- UI 09 自定义cell
- UICollectionview实现自定义cell的移动删除
- iOS开发UI篇 -- 0401微博主页-自定义cell
- IOS UI tableView 自定义cell的内容不显示
- iOS开发UI篇 -- UICollectionView
- iOS 关于UICollectionView的cell重用问题
- iOS开发 怎么删除UICollectionView的cell
- IOS UItableview UIcollectionview cell高度自适应
- [iOS]UICollectionView设置cell之间的间距
- Gartner对微服务的解读,比较全面
- windbg基本知识和常用命令
- android混淆打包、反编译、重新打包签名
- 第八周项目3-顺序串算法(1)
- js中获取事件对象的方法小结
- iOS UI 18 uicollectionview和自定义cell
- hdu 1207 汉诺塔II
- GCD实际应用
- 独家直播双十一全网动态?前黑客“劳改”带你玩转大数据
- [leetcode] 231. Power of Two 解题报告
- iOS UI 20 音乐播放器
- mac下已安装的ssh的id_rsa.pub文件位置
- Writing your first Django app, part 1
- iOS UI 21 动画