

只需简单的 2 步即可快速集成此控件
self.banner = [[ZYBannerView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)]; self.banner.dataSource = self; [self.view addSubview:self.banner]; // 返回 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; NO (此属性为YES时, shouldLoop属性会被置为NO)@property (nonatomic, assign) IBInspectable BOOL showFooter; NO@property (nonatomic, assign) IBInspectable BOOL autoScroll; @property (nonatomic, assign) IBInspectable NSTimeInterval scrollInterval; pageIndicatorTintColor, currentPageIndicatorTintColor@property (nonatomic, strong, readonly) UIPageControl *pageControl; @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 中直接设置
- (void)reloadData; viewWillAppear:和viewWillDisappear:中分别调用这两个方法, 使得 Banner 没有显示的时候定时器不会一直占用着资源.- (void)startTimer; - (void)stopTimer; - (NSInteger)numberOfItemsInBanner:(ZYBannerView *)banner; index所要显示的 View. 这个 View 可以是简单的一个 UIImageView, 也可以是自定义的一个复杂的 View. View 的大小自动布局为 Banner 的大小, 无需对此 View 设置frame [ required ]- (UIView *)banner:(ZYBannerView *)banner viewForItemAtIndex:(NSInteger)index; ZYBannerFooterStateIdle正常状态 \ ZYBannerFooterStateTrigger触发状态)显示的文字 [ optional ]- (NSString *)banner:(ZYBannerView *)banner titleForFooterWithState:(ZYBannerFooterState)footerState; index个 Item 时, 此代理方法将被调用 [ optional ]- (void)banner:(ZYBannerView *)banner didSelectItemAtIndex:(NSInteger)index; - (void)bannerFooterDidTrigger:(ZYBannerView *)banner; 1.使用 CocoaPods:
pod 'ZYBannerView' 2.手动添加:
#import "ZYBannerView.h"ZYBannerView is released under the MIT license. See LICENSE for details.
1 ljcarsenal 2016-09-05 13:50:20 +08:00 via Android 我猜 zy 是你名字?不过 ios 的开源库似乎用作者名字起名是很普遍的现象? |
2 kengsir OP 原作者或者 github 地址可以前往原链接查询到~~ |