瀑布流-UICollectionView 的从新布局,动态加载HTML数据,HTML数据的解析和UICollectionViewFlowLayout的从布

本文介绍如何创建一个自定义的UICollectionView瀑布流布局,包括布局的重新创建和动态加载HTML数据。详细讲解了如何实现布局的代理方法,以及如何在UICollectionViewCell中解析并展示HTML内容。此外,还提供了项目的完整下载链接。
摘要由CSDN通过智能技术生成

               瀑布流是现在,APP开发的热点。它的出现,极大的让列表出现多种形态。不在是以前单纯的那个模式。今天,我们讲解怎么重新布局(也可以不用布局),和加载动态的HTML的数据,和数据的刷新,进行创建瀑布流。其实,有两种方法创建,但是,第一种,有点问题,但也是可以的。下面我们就开始进入主题:

第一步:我们首先创建 UICollectionView对象

#pragma mark  创建 CollectionView

-(void)makeCollectionView{

    //实现瀑布流 ,我们要从新布局,那就要从新创建 UICollectionViewFlowLayout

    // 创建一个布局的对象

    ZSJ_PBL_CollectionViewFlowLayout * ZSJ_FlowLayout = [[ZSJ_PBL_CollectionViewFlowLayoutalloc]init];

    //实现其代理

    ZSJ_FlowLayout.delegate = self;

    //创建UICollectionView的对象

    _CollectView_zsj = [[UICollectionViewalloc]initWithFrame:CGRectMake(0,64, self.view.frame.size.width,self.view.frame.size.height-108)collectionViewLayout:ZSJ_FlowLayout];

    //  设置 UICollectionView  的一些属性

    //两个代理

    _CollectView_zsj.delegate =self;

    _CollectView_zsj.dataSource =self;

    //设置 UICollectionView的背景色

    _CollectView_zsj.backgroundColor = [UIColorcolorWithRed:220/255.0green:220/255.0blue:220/255.0alpha:1];

    // 注册 cell

    [_CollectView_zsjregisterClass:[ZSJ_CollectionViewCellclass] forCellWithReuseIdentifier:CCELL_ID];

    // UICollectionView添加到主视图控制器上

    [self.viewaddSubview:_CollectView_zsj];

    

}


第二步:我们要实现 UICollectionView的一些代理方法

#pragma mark  实现  UICollectionView的代理方法

/**************************************************************/

//这个方法是处理 UICollectionView 返回 cell 的数量

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

    return_fashionModelArray.count;

}

/**************************************************************/

//这个是 UICollectionView  cell

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

    //创建 cell对象

    ZSJ_CollectionViewCell * Cell = [collectionViewdequeueReusableCellWithReuseIdentifier: CCELL_ID  forIndexPath:indexPath];

    //可以传递数据

    ZSJ_Modle * Model = _fashionModelArray[indexPath.row];

    [Cell sourc:Model];

    //实现收藏点击事件

    [Cell.collectbuttonaddTarget:selfaction:@selector(collectClick:)forControlEvents:UIControlEventTouchUpInside];

    //添加标记

    Cell.collectbutton.tag = indexPath.row;

    Cell.sharebutton.tag = indexPath.row;

    //实现分享点击事件

    [Cell.sharebuttonaddTarget:selfaction:@selector(shareClick:)forControlEvents:UIControlEventTouchUpInside];

    

    //返回你定义好的Cell

    return Cell;

    

}

/**************************************************************/

//这个是  UICollectionView cell被选中 触发的方法

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

    

}

/**************************************************************/

//这个方法是  UICollectionView是否可选择,即是 可否交互。

-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    return YES;

}


第三步:我们要创建布局文件,并创建其对象,和其必要实现的方法

1、布局文件,声明的方法和属性

//

//  ZSJ_PBL_CollectionViewFlowLayout.h

//  瀑布流_ZSJMeth

//

//  Created by 周双建 on 15/12/9.

//  Copyright © 2015周双建. All rights reserved.

//


#import <UIKit/UIKit.h>

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值