自动定义瀑布流控件的实现<一>

自定义瀑布流控件的流程完全是仿照系统控件UITableView进行的。
我们知道UITableView控件向外界展示出来,需要询问它的的数据源代理对象三个问题:
1> 自己有多少个分区;
2> 每个分区有多少行;
3> 每一行显示什么类型的tableViewCell.
这就是所谓的三问,数据源代理对象回答完这三个问题之后,tableView就知道自身的整体构造,然后按照要求显示出来.

按照这个思路,我们来自定义一个瀑布流控件:
要点1:waterFlowView:UIScrollView 自定义控件继承自滚动视图

WaterFlowView.h

#import <UIKit/UIKit.h>
/** cell的各种不同的内边距以枚举的形式全部列举出来 */
typedef  enum{
    WaterFlowViewForMarginTypeTop,  
    WaterFlowViewForMarginTypeBottom,
    WaterFlowViewForMarginTypeLeft,
    WaterFlowViewForMarginTypeRight,//前面四种是cell与父控件之间的边距
    WaterFlowViewForMarginTypeRow,
    WaterFlowViewForMarginTypeColum,//后面两种是cell与cell之间的边距
}WaterFlowViewForMarginType;

@class WaterFlowView;
@class WaterFlowViewCell;

/** 数据源协议 */
@protocol WaterFlowViewDataSource <NSObject>
@required
//有多少cell
- (NSUInteger)numberOfCellsInWaterFlowView:(WaterFlowView*)waterView;
//指定位置显示什么类型的cell
- (WaterFlowViewCell*)waterFlowView:(WaterFlowView*)waterFlowView cellAtIndex:(NSUInteger)index;

@optional
//有多少列(默认显示3列)
- (NSUInteger)numberColumsInWaterFlowView:(WaterFlowView*)waterFlowView;
@end

/** 代理协议 */
@protocol WaterFlowViewDelegate <UIScrollViewDelegate>
@optional
//指定位置的cell的显示高度
- (CGFloat)waterFlowView:(WaterFlowView*)waterFlowView heightAtIndex:(NSUInteger)index;
//点击指定位置的cell触发
- (void)waterFlowView:(WaterFlowView*)waterFlowView didSelectedAtIndex:(NSUInteger)index;
//返回cell的各种内边距 
- (CGFloat)waterFlowView:(WaterFlowView *)waterFlowView marginForType:(WaterFlowViewForMarginType)type;
@end


@interface WaterFlowView : UIScrollView

@property(nonatomic,weak)id<WaterFlowViewDataSource> dataSource;
@property(nonatomic,weak)id<WaterFlowViewDelegate>   delegate1;

/** 刷新界面数据 */
- (void)reloadData;
[刷新的要点](http://img.blog.csdn.net/20151128185716046)
@end

WaterViewFlow.m

#import "WaterFlowView.h"
#import "WaterFlowViewCell.h"

#define waterFlowViewDefaultNumberOfColums 3;
#define waterFlowViewDefaultMargin         10;
#define waterFlowViewDefaultCellHeight     75;


@interface WaterFlowView ()</
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值