[控件分享] ZYBannerView - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
kengsir
V2EX    分享创造

[控件分享] ZYBannerView

  •  
  •   < href="/member/kengsir">kengsir 2016-09-05 09:41:45 +08:00 2481 次点击
    这是一个创建于 3375 天前的主题,其中的信息可能已经有所发展或是发生改变。

    DEMO 下载: http://code4app.com/forum.php?mod=viewthread&tid=10390&extra=page%3D3%26filter%3Dsortid%26orderby%3Ddateline%26sortid%3D1

    CocoaPods CocoaPods Support

    ZYBannerView

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

    Features

    • [x] 显示的内容可高度自定义
    • [x] 可配置循环滚动效果
    • [x] 可配置是否自动滚动, 以及自动滚动时间间隔
    • [x] 显示\隐藏 Footer
    • [x] 自定义 PageControl 属性
    • [x] 支持在 Storyboard\xib 中创建并配置其属性
    • [x] 支持 Autolayout

    Usage

    Basic Usage

    只需简单的 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; } 

    Advanced Usage

    各种属性与方法的介绍

    Property

    • 是否需要循环滚动, 默认为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, 可自由配置其属性, 例如pageIndicatorTintColor, currentPageIndicatorTintColor
    @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 : shouldLoop, showFooter, autoScroll, scrollInterval, dataSource, delegate 均可支持在 Storyboard\xib 中直接设置

    Method

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

    DataSource

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

    Delegate

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

    Requirements

    • iOS 7.0+
    • Xcode 5.0+

    Installation

    1.使用 CocoaPods:

    pod 'ZYBannerView' 

    2.手动添加:

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

    License

    ZYBannerView is released under the MIT license. See LICENSE for details.

    2 条回复    2016-09-05 13:59:34 +08:00
    ljcarsenal
        1
    ljcarsenal  
       2016-09-05 13:50:20 +08:00 via Android
    我猜 zy 是你名字?不过 ios 的开源库似乎用作者名字起名是很普遍的现象?
    kengsir
        2
    kengsir  
    OP
       2016-09-05 13:59:34 +08:00
    原作者或者 github 地址可以前往原链接查询到~~
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     901 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 21:23 PVG 05:23 LAX 13:23 JFK 16:23
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86