自定义轮播图

因项目需求,会碰见像下图这样混排的轮播图,于是决定重写一个可以自定义每个pageView的轮播图,按照tableView的使用方法开始了造轮子,使用方法和tableView类似,同时支持重用pageView,横向和纵向。

自定义轮播图_第1张图片
Snip20190629_99.png
自定义轮播图_第2张图片
image.png

1、使用方法

@property (nonatomic, assign) BOOL dragEnable;  //default YES
@property (nonatomic, assign) CGFloat interval; //auto scroll time
@property (nonatomic, weak) iddelegate;
@property (nonatomic, weak) iddataSource;

/** 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、数据源方法

/* 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 *)viewForSupplementaryView:(HHRotateView *)rotateView;
/* return a layout object */
- (HHSupplementViewLayout *)layoutForSupplementaryView;

viewForSupplementaryView为获取pageControl对象
HHSupplementViewLayout对象为存储的pageControl的布局对象

- (HHSupplementViewLayout *)layoutForSupplementaryView
{
//距离底部10pt,中心x与父视图对其
    return HHSupplementViewLayout.new.bottom(-10).centX(0);
}

3、 效果图

自定义轮播图_第3张图片
Untitled.gif

详见Demo git地址

你可能感兴趣的:(自定义轮播图)