自定義輪播圖

因項(xiàng)目需求,會(huì)碰見像下圖這樣混排的輪播圖,于是決定重寫一個(gè)可以自定義每個(gè)pageView的輪播圖,按照tableView的使用方法開始了造輪子,使用方法和tableView類似,同時(shí)支持重用pageView,橫向和縱向。

Snip20190629_99.png
image.png

1、使用方法

@property (nonatomic, assign) BOOL dragEnable;  //default YES
@property (nonatomic, assign) CGFloat interval; //auto scroll time
@property (nonatomic, weak) id<HHRotateViewDelegate>delegate;
@property (nonatomic, weak) id<HHRotateViewDataSrouce>dataSource;

/** init method  */
- (instancetype)initWithFrame:(CGRect)frame style:(HHRotateViewStyle)style;

/** must to register cell class */
- (void)registerClass:(Class)cellClass identifier:(NSString *)identifier;

/** need to dequeue cell class, support reuse cell */
- (__kindof HHRotateViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier index:(NSInteger)index;

/** reload cell it will call dataSource method */
- (void)reloadData;

2、數(shù)據(jù)源方法

/* must to implementation */
- (NSInteger)numberOfRowsInRotateView:(HHRotateView *)rotateView;

/* must to implementation call `dequeueReusableCellWithIdentifier` */
- (__kindof HHRotateViewCell *)rotateView:(HHRotateView *)rotateView cellForRowAtIndex:(NSInteger)index;

@optional

/* return a View like UIPageControl need to conform `HHRotateViewDelegate` */
- (__kindof UIView <HHRotateViewDelegate>*)viewForSupplementaryView:(HHRotateView *)rotateView;
/* return a layout object */
- (HHSupplementViewLayout *)layoutForSupplementaryView;

viewForSupplementaryView為獲取pageControl對(duì)象
HHSupplementViewLayout對(duì)象為存儲(chǔ)的pageControl的布局對(duì)象

- (HHSupplementViewLayout *)layoutForSupplementaryView
{
//距離底部10pt,中心x與父視圖對(duì)其
    return HHSupplementViewLayout.new.bottom(-10).centX(0);
}

3、 效果圖

Untitled.gif

詳見Demo git地址

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容