ZYBannerView 1.1.6

ZYBannerView 1.1.6

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2020年3月

zzyspace维护。



  • zy_zhang

CocoaPods  CocoaPods  Support 

ZYBannerView

  • 一个简单易用的轮播控件,基于UICollectionView实现。

特性

  • 显示的内容可高度自定义
  • 可配置循环滚动效果
  • 可配置是否自动滚动,以及自动滚动时间间隔
  • 显示/隐藏页脚
  • 自定义翻页控件属性
  • 支持在Storyboard/xib中创建并配置其属性
  • 支持Autolayout

使用方法

基本用法

只需简单的2步即可快速集成此控件

1.创建Banner并设置数据源

self.banner = [[ZYBannerView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
self.banner.dataSource = self;
[self.view addSubview:self.banner];

2.实现数据源方法

// 返回Banner需要显示Item(View)的个数
- (NSInteger)numberOfItemsInBanner:(ZYBannerView *)banner
{
    return 3;
}

// 返回Banner在不同的index所要显示的View
- (UIView *)banner:(ZYBannerView *)banner viewForItemAtIndex:(NSInteger)index
{
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xxx"]];
    return imageView;
}

高级用法

各种属性与方法的介绍

属性

  • 是否需要循环滚动,默认为NO
@property (nonatomic, assign) IBInspectable BOOL shouldLoop;
  • 是否显示Footer,默认为NO (此属性为YES时,shouldLoop属性会被置为NO)
@property (nonatomic, assign) IBInspectable BOOL showFooter;
  • 是否自动滑动,默认为NO
@property (nonatomic, assign) IBInspectable BOOL autoScroll;
  • 自动滑动间隔时间(s),默认为 3.0
@property (nonatomic, assign) IBInspectable NSTimeInterval scrollInterval;
  • Banner上显示的PageControl,可自由配置其属性,例如pageIndicatorTintColorcurrentPageIndicatorTintColor
@property (nonatomic, strong, readonly) UIPageControl *pageControl;
  • 根据需要设置PageControl的frame,若不设置或者设置为CGRectZero,则使用默认位置
@property (nonatomic, assign, readwrite)  CGRect pageControlFrame;
  • 数据源与代理
@property (nonatomic, weak) IBOutlet id<ZYBannerViewDataSource> dataSource;
@property (nonatomic, weak) IBOutlet id<ZYBannerViewDelegate> delegate;

NOTE : shouldLoopshowFooterautoScrollscrollIntervaldataSourcedelegate 均可支持在Storyboard/xib中直接设置

方法

  • 刷新Banner的数据
- (void)reloadData;
  • 开始/停止用于自动滚动的定时器。比如可以在viewWillAppear:viewWillDisappear:中分别调用这两个方法,使得Banner没有显示的时候定时器不会一直占用着资源。
- (void)startTimer;
- (void)stopTimer;

数据源

  • 返回需要显示的Item(View)个数【必须】
- (NSInteger)numberOfItemsInBanner:(ZYBannerView *)banner;
  • 返回在不同index位置显示的View。这个View可以是简单的UIImageView,也可以是自定义的复杂View。View的大小默认布局为Banner的大小,无需对此View设置frame【必须】
- (UIView *)banner:(ZYBannerView *)banner viewForItemAtIndex:(NSInteger)index;
  • 返回Footer在不同状态下(ZYBannerFooterStateIdle正常状态 \ ZYBannerFooterStateTrigger触发状态)显示的文字【可选】
- (NSString *)banner:(ZYBannerView *)banner titleForFooterWithState:(ZYBannerFooterState)footerState;

委托

  • 用户点击了第index个Item时,此代理方法将被调用【可选】
- (void)banner:(ZYBannerView *)banner didSelectItemAtIndex:(NSInteger)index;
  • 用户拖动Footer并达到触发点时,此代理方法将被调用【可选】
- (void)bannerFooterDidTrigger:(ZYBannerView *)banner;

要求

  • iOS 7.0+
  • Xcode 5.0+

安装

1.使用CocoaPods

pod 'ZYBannerView'

2.手动添加

  • 将ZYBannerView文件夹拖拽到项目中
  • 导入头文件:#import "ZYBannerView.h"

许可证

ZYBannerView遵循MIT许可证发布。详细信息见LICENSE。

在C#中使用ZYBannerView

想要将ZYBannerView集成到Xamarin项目中?请查看ZYBannerView_Xamarin(感谢jingliancui)。