iOS 瀑布流封裝

2021-08-15 10:20:46 字數 2993 閱讀 1098

功能描述:wslwaterflowlayout 是在繼承於uicollectionviewlayout的基礎上封裝的帶頭腳檢視的瀑布流控制項。目前支援豎向瀑布流(item等寬不等高、支援頭腳檢視)、水平瀑布流(item等高不等寬 不支援頭腳檢視)、豎向瀑布流( item等高不等寬、支援頭腳檢視)三種樣式的瀑布流布局。

/** 初始化 生成每個檢視的布局資訊*/

-(void)preparelayout;

/** 決定一段區域所有cell和頭尾檢視的布局屬性*/

-(nsarray*)layoutattributesforelementsinrect:(cgrect)rect ;

/** 返回indexpath位置cell對應的布局屬性*/

-(uicollectionviewlayoutattributes *)layoutattributesforitematindexpath:(nsindexpath *)indexpath;

/** 返回indexpath位置頭和腳檢視對應的布局屬性*/

- (uicollectionviewlayoutattributes *)layoutattributesforsupplementaryviewofkind:(nsstring *)elementkind atindexpath:(nsindexpath *)indexpath;

//返回內容高度

-(cgsize)collectionviewcontentsize;

typedef enum  wslflowlayoutstyle;//樣式

@class wslwaterflowlayout;

@protocol wslwaterflowlayoutdelegate /** 豎向瀑布流 item等寬不等高 */

-(cgfloat)waterflowlayout:(wslwaterflowlayout *)waterflowlayout heightforitematindexpath:(nsindexpath *)indexpath itemwidth:(cgfloat)itemwidth;

/** 水平瀑布流 item等高不等寬 */

-(cgfloat)waterflowlayout:(wslwaterflowlayout *)waterflowlayout widthforitematindexpath:(nsindexpath *)indexpath itemheight:(cgfloat)itemheight;

/** 豎向瀑布流 item等高不等寬 列數、行數無用 */

- (cgsize)waterflowlayout:(wslwaterflowlayout *)waterflowlayout sizeforitematindexpath:(nsindexpath *)indexpath;

/** 頭檢視size */

-(cgsize )waterflowlayout:(wslwaterflowlayout *)waterflowlayout sizeforheaderviewinsection:(nsinteger)section;

/** 腳檢視size */

-(cgsize )waterflowlayout:(wslwaterflowlayout *)waterflowlayout sizeforfooterviewinsection:(nsinteger)section;

@optional

//以下都有預設值

/** 列數*/

-(cgfloat)columncountinwaterflowlayout:(wslwaterflowlayout *)waterflowlayout;

/** 行數*/

-(cgfloat)rowcountinwaterflowlayout:(wslwaterflowlayout *)waterflowlayout;

/** 列間距*/

-(cgfloat)columnmargininwaterflowlayout:(wslwaterflowlayout *)waterflowlayout;

/** 行間距*/

-(cgfloat)rowmargininwaterflowlayout:(wslwaterflowlayout *)waterflowlayout;

/** 邊緣之間的間距*/

-(uiedgeinsets)edgeinsetinwaterflowlayout:(wslwaterflowlayout *)waterflowlayout;

@end

@inte***ce wslwaterflowlayout : uicollectionviewlayout

/** delegate*/

@property (nonatomic, weak) iddelegate;

/** 瀑布流樣式*/

@property (nonatomic, assign) wslflowlayoutstyle flowlayoutstyle;

@end

初始化僅三行**,只需設定**和樣式,item的大小、頭腳檢視的大小、行列數以及間距都可以在對應樣式的**方法中自定義,然後設定為uicollectionview的自動流水布局樣式,並結合uicollectionview的用法使用,詳情看示例

wslwaterflowlayout * _flow = [[wslwaterflowlayout alloc] init];

_flow.delegate = self;

_flow.flowlayoutstyle = wslverticalwaterflow;

好了,有需要的直接去這裡瞅瞅吧wslwaterflowlayout

iOS 瀑布流封裝

位址如下 功能描述 wslwaterflowlayout 是在繼承於uicollectionviewlayout的基礎上封裝的帶頭腳檢視的瀑布流控制項。目前支援豎向瀑布流 item等寬不等高 支援頭腳檢視 水平瀑布流 item等高不等寬 不支援頭腳檢視 豎向瀑布流 item等高不等寬 支援頭腳檢視 ...

iOS學習筆記 瀑布流封裝

最近學習了瀑布流布局,是用collectionview實現的。首先說說設計思路,用collectionview做出來的瀑布流是固定行數或者列數的。以現在主流固定列數為例,每個item就是固定寬,不固定高,同時每個item之間的間距是固定的,那麼每行的y值計算就需要通過前一行的最短的item來確定。既...

js瀑布流,簡單封裝

乙個很簡單的瀑布流載入,當滾動條滾動到底部時自動載入,先 敬上 lang en charset utf 8 demotitle head li pinterest wrap pinterest wrap ul pinterest wrap ulli style class pinterest wra...