UI2_UICollectionViewPicture
// AppDelegate.m
// UI2_UICollectionViewPicture
//
// Created by zhangxueming on 15/7/16.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *root = [[ViewController alloc] init];
UINavigationController *nav =[[UINavigationController alloc] initWithRootViewController:root];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor]; return YES;
}
// ViewController.h
// UI2_UICollectionViewPicture
//
// Created by zhangxueming on 15/7/16.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end //
// ViewController.m
// UI2_UICollectionViewPicture
//
// Created by zhangxueming on 15/7/16.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h" #define kCellReuseId @"cellID" @interface ViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
{
UICollectionView *_collectionView;
NSMutableArray *_dataList;
} @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//创建数据源
[self createDataList];
//创建UI
[self createUI];
//代理
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
} - (void)createDataList
{
_dataList = [NSMutableArray array];
for (int i=0; i<10; i++) {
NSString *name = [NSString stringWithFormat:@"superCar%i", i];
NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[_dataList addObject:image];
}
} //创建UI - (void)createUI
{
//创建布局对象
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
//上下左右边距
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
//cell的大小
layout.itemSize = CGSizeMake(150, 100);
//cell横向间距
layout.minimumInteritemSpacing = 20;
//cell纵向间距
layout.minimumLineSpacing = 30;
//创建collectionView
_collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor whiteColor];
//设置代理
_collectionView.delegate = self;
_collectionView.dataSource = self; //注册cell [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCellReuseId]; [self.view addSubview:_collectionView];
} #pragma mark ---delegate--- //返回分区个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
} //返回分区cell 的个数 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return _dataList.count;
} //返回cell - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellReuseId forIndexPath:indexPath]; for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
} UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 100)];
imageView.image = _dataList[indexPath.item];
[cell.contentView addSubview:imageView]; return cell;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
UI2_UICollectionViewPicture的更多相关文章
随机推荐
- 在Android上使用ZXing识别条形码/二维码
越来越多的手机具备自动对焦的拍摄功能,这也意味着这些手机可以具备条码扫描的功能.......手机具备条码扫描的功能,可以优化购物流程,快速存储电子名片(二维码)等. 本文使用ZXing 1.6实现条码 ...
- 解决win7 64位中 魔方与TortoiseSVN的冲突解决【2014-02-10】
原文地址:http://www.cnblogs.com/hbbbs/p/3542479.html 现象 启动后弹出SendRpt:Error的提示框,然后变成soap1.2 fault.关闭后,又会自 ...
- Visual Studio Code 1.0.1 for python
1. 安 F1健 ext install python E:\test\.vscode下的三个文件 2.launch.json { "version": "0.1.0&q ...
- 终端I/O之特殊输入字符
POSIX.1定义了11个在输入时作特殊处理的字符.实现定义了另外一些特殊字符.表18-6摘要列出了这些特殊字符. 表18-6 终端特殊输入字符 在POSIX.1的11个特殊字符中,可将其中9个更改为 ...
- CF 335A(Banana-贪心-priority_queue是大根堆)
A. Banana time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- IOS 开发中判断NSString是否为空字符
//当 请求网络 或者获取其他返回数据 首先 要做一次判断 数据是否为空 防止程序崩溃 程序崩溃 好比拿刀扎在程序员的心啊- if(为空) { 做提示对话框等操作 } else { 正常执行 } - ...
- [Arduino] 在串口读取多个字符串,并且转换为数字数组
功能如题目.在串口收到逗号分割的6串数字比如100,200,45,4,87,99然后在6个PWM端口3, 5, 6, 9, 10, 11输出对应PWM值代码注释很详细了,就不再说明了. //定义一个c ...
- Laravel自学第一课:laravel下载与安装
本地安装laravel,php环境要配置好,推荐xmapp一键搭建. 1.程序包直接从官方下载,官方开源地址:https://github.com/laravel/laravel(当然也可从此网站:h ...
- C# 递归程序 获取某个节点下的全部子节点
/// <summary> /// 获取组织结构树 /// </summary> /// <param name="list"></par ...
- Android小项目之八 界面细节
------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...