博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ObObjective-c 采集试图 UICollection
阅读量:7055 次
发布时间:2019-06-28

本文共 3748 字,大约阅读时间需要 12 分钟。

hot3.png

//

//  ViewController.m

//  12.14 采集试图 UICollection

//

//  Created by DC017 on 15/12/14.

//  Copyright © 2015 DC017. All rights reserved.

//

#import "ViewController.h"

ViewController ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

{

    UICollectionView * collection;

    //重用标示符

    NSString * CellIdenntifier;

    float f;

    

}

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    CellIdenntifier=@"标示";

    [self layout];

    f=0;

  

}

-(void)layout{

    UICollectionViewFlowLayout *bujufangan=[[UICollectionViewFlowLayout alloc]init];

     //设置滚动方向(垂直或水平)

          //翻页

    //collection.pagingEnabled=YES;

    

    collection=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 20, 375, 647) collectionViewLayout:bujufangan];

    collection.backgroundColor=[UIColor orangeColor];

   

    //bujufangan.scrollDirection=//滚动方向

     //水平滚动

    bujufangan.scrollDirection=UICollectionViewScrollDirectionHorizontal;

    [self.view addSubview:collection];

    

    collection.delegate=self;

    collection.dataSource=self;

    //注册采集试图所使用的cell类,并设置标示符

    

    [collection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:CellIdenntifier];

    

   

    

}

#pragma mark 设置Ceel

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    

    

    UICollectionViewCell *cell=[collection dequeueReusableCellWithReuseIdentifier:CellIdenntifier forIndexPath:indexPath];

   

    cell.backgroundColor=[UIColor colorWithWhite:(float)indexPath.row/(66*1.0) alpha:1];

    

    //选中后变红色

//    UIView* view=[[UIView alloc]initWithFrame:cell.bounds];

//    view.backgroundColor=[UIColor redColor];

//    cell.selectedBackgroundView=view;

    

    return cell;

}

#pragma marc 设置单个section 里的cell

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return  66;

}

#pragma mark 点击事件

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    

    

    NSLog(@"%ld",indexPath.row);

}

#pragma mark 自定义cell 尺寸

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

    f=f+2;

    return CGSizeMake(f, f);

    

}

#pragma mark 定义每个section 的内边距

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

    

    return UIEdgeInsetsMake(100, 40, 0, 40);

}

#pragma mark 设定cell行间距

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{

    return 600;

}

#pragma mark 设置列间距

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

    return 20;

}

//交互

//1.手指按下某个cell

//2.shouldHighlightIemAtIndexPach(如果返回yes,则向下执行,否则终止);

//3.didHightlightItemAtIndexPath(高亮)

//4.手指松开

//5.didUnhighlghtItemAtIndexPath(取消高亮);

//6.shouldSelectItemAtIndexPath(如果返回yes,则继续向下执行,否则终止)

//7.didSelectItemAtIndexPath(执行选择事件)

-(void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{

    

    

    

}

-(void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{

    [collectionView cellForItemAtIndexPath:indexPath].backgroundColor = [UIColor whiteColor];

}

#pragma mark 页眉  页脚  水平width  垂直height

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{

    return CGSizeMake(200,10 );

   

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end

转载于:https://my.oschina.net/u/2483781/blog/544488

你可能感兴趣的文章
linux+nginx+tomcat负载均衡,实现session同步
查看>>
初始JavaScript Promises之二
查看>>
IntelliJ IDEA常见问题解决办法汇总
查看>>
[LeetCode] Container With Most Water 装最多水的容器
查看>>
poj 3624 Charm Bracelet 背包DP
查看>>
用dedecms自定义表单创建简易自助预约系统
查看>>
读《了解你的学生》有感
查看>>
dedecms /member/flink_main.php SQL Injection Vul
查看>>
Dropbox Folder Sync – 让 Dropbox 同步任意文件夹
查看>>
PHP 网页爬虫
查看>>
sql字符串的拼接 (字符串和二进制,erlang的mysql驱动)
查看>>
WinSocket同时接入量的疑惑(求解...)
查看>>
终端I/O之终端窗口的大小
查看>>
《C#高级编程》学习笔记------C#中的事件和委托
查看>>
sql-mysql
查看>>
转 管线开发
查看>>
Struts2学习笔记1
查看>>
远程首次连接mysql速度慢的解决方法:skip-name-resolve取消DNS的反向解析(转)
查看>>
php栈数据结构和括号匹配算法
查看>>
Visual Studio 2013 的 Xamarin 安装教程
查看>>