LCBannerView 2.1.1

LCBannerView 2.1.1

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布最新发布2016年10月

LeoLeo 维护。



🔥一个非常受欢迎且高度定制的横幅视图!无限循环!

LCBannerView

In me the tiger sniffs the rose.

心有猛虎,细嗅蔷薇。

欢迎来到我的博客: http://LeoDev.me

中文介绍

介绍

这是用于展示广告或信息的界面。

您可以使用来自 本地互联网 的图片。

并且它不会影响其他滚动视图的 scrollsToTop 属性。

如果您觉得好,请给我一个星标,非常感谢!⭐️

安装

LCBannerView 可在 CocoaPods 上使用。只需将以下内容添加到您的项目 Podfile

pod "LCBannerView"  # Podfile

用法

  • 通过包含以下导入使用

    #import "LCBannerView.h"
  • 演示代码

    // 1. From internet
    [scrollView addSubview:({
    
        LCBannerView *bannerView = [LCBannerView bannerViewWithFrame:CGRectMake(0, 300.0f, [UIScreen mainScreen].bounds.size.width, 200.0f)
                                                            delegate:self
                                                           imageURLs:URLs
                                                placeholderImageName:nil
                                                        timeInterval:2.0f
                                       currentPageIndicatorTintColor:[UIColor redColor]
                                              pageIndicatorTintColor:[UIColor whiteColor]];
        bannerView.pageDistance = 20.0f;
        bannerView;
    })];
    
    // 2. From local
    // If you using images from local, you should let images named: `[email protected]`, `[email protected]`...
    // Than, you just give me a image named: `banner`. 😜
    [scrollView addSubview:({
    
        LCBannerView *bannerView = [[LCBannerView alloc] initWithFrame:CGRectMake(0, 20.0f, [UIScreen mainScreen].bounds.size.width, 200.0f)
                                                              delegate:self
                                                             imageName:@"banner"
                                                                 count:3
                                                          timeInterval:3.0f
                                         currentPageIndicatorTintColor:[UIColor orangeColor]
                                                pageIndicatorTintColor:[UIColor whiteColor]];
        bannerView;
    })];
  • 运行演示的建议

    您应该在演示代码中注释掉 block 代码或 delegate 代码中的一个,这将帮助您更清晰地阅读代码。

    更多信息见以下两个要点。

  • Block: (@optional)

    @property (nonatomic, copy) LCBannerViewDidClickedImageIndexBlock didClickedImageIndexBlock;
    
    @property (nonatomic, copy) LCBannerViewDidScrollToIndexBlock didScrollToIndexBlock;

    例如

    bannerView.didClickedImageIndexBlock = ^(LCBannerView *bannerView, NSInteger index) {
    
        NSLog(@"Block: Clicked image in %p at index: %d", bannerView, (int)index);
    };
    
    bannerView.didScrollToIndexBlock = ^(LCBannerView *bannerView, NSInteger index) {
    
        NSLog(@"Block: Scrolled in %p to index: %d", bannerView, (int)index);
    };
    
    // Logs
    2016-07-29 15:41:00.344 LCBannerViewDemo[3251:295032] Block: Scrolled in 0x7ff473538ec0 to index: 1
    2016-07-29 15:41:03.343 LCBannerViewDemo[3251:295032] Block: Scrolled in 0x7ff473538ec0 to index: 2
    2016-07-29 15:41:05.132 LCBannerViewDemo[3251:295032] Block: Clicked image in 0x7ff473538ec0 at index: 2
    2016-07-29 15:41:06.344 LCBannerViewDemo[3251:295032] Block: Scrolled in 0x7ff473538ec0 to index: 0
    2016-07-29 15:41:09.344 LCBannerViewDemo[3251:295032] Block: Scrolled in 0x7ff473538ec0 to index: 1
    2016-07-29 15:41:12.342 LCBannerViewDemo[3251:295032] Block: Scrolled in 0x7ff473538ec0 to index: 2
  • Delegate: (@optional)

    - (void)bannerView:(LCBannerView *)bannerView didClickedImageIndex:(NSInteger)index;
    
    - (void)bannerView:(LCBannerView *)bannerView didScrollToIndex:(NSInteger)index;

    例如

    - (void)bannerView:(LCBannerView *)bannerView didClickedImageIndex:(NSInteger)index {
    
        NSLog(@"Delegate: Clicked image in %p at index: %d", bannerView, (int)index);
    }
    
    - (void)bannerView:(LCBannerView *)bannerView didScrollToIndex:(NSInteger)index {
    
        NSLog(@"Delegate: Scrolled in %p to index: %d", bannerView, (int)index);
    }
    
    // Logs
    2016-07-29 15:41:45.296 LCBannerViewDemo[3293:296197] Delegate: Scrolled in 0x7f915b7349b0 to index: 1
    2016-07-29 15:41:47.300 LCBannerViewDemo[3293:296197] Delegate: Scrolled in 0x7f915b7349b0 to index: 0
    2016-07-29 15:41:48.429 LCBannerViewDemo[3293:296197] Delegate: Clicked image in 0x7f915b7349b0 at index: 0
    2016-07-29 15:41:49.308 LCBannerViewDemo[3293:296197] Delegate: Scrolled in 0x7f915b7349b0 to index: 1
    2016-07-29 15:41:51.297 LCBannerViewDemo[3293:296197] Delegate: Scrolled in 0x7f915b7349b0 to index: 0
  • 自定义参数

    // Distance to bottom of pageControl. Default is `10.0f`.
    @property (nonatomic, assign) CGFloat   pageDistance;
    
    // Not allow scrolling. Default `No`, allow scrolling.
    @property (nonatomic, assign) BOOL      notScrolling;

修改日志

V 2.1.1

  • 隐藏 pageControl 支持

    // Hide or show pageControl. Default is `NO`, show pageControl.
    @property (nonatomic, assign) BOOL      hidePageControl;

V 2.1.0

  • 实现要求:由 问题 6 by skyboy1342 提出的问题。

    现在,您可以通过 BlockDelegate 获取点击图片的索引和滚动到的索引,请参见 用法

  • 计算:当您将 bannerView 添加到 SUPERVIEW 时,didScrollToIndex 方法不会在索引 0 上调用,因为还没有滚动过,而且事实上您知道索引是 0,因为您这样做。

V 2.0.0 (⚠️重要)

  • 修复 问题 5,感谢 MVakas

  • 更改一些属性和方法的名字

    // Properties' name.
    @property (nonatomic, assign) CGFloat timerInterval;
    ->
    @property (nonatomic, assign) CGFloat timeInterval;
    
    @property (nonatomic, copy  ) NSString  *placeholderImage;
    ->
    @property (nonatomic, copy  ) NSString  *placeholderImageName;
    
    // All methods' name.
    timerInterval -> timeInterval
    placeholderImage -> placeholderImageName

V 1.2.5

  • 更新 README 和一些文档。

V 1.2.2

  • 更新 CocoaPods 源 URL。

版本 1.2.0

  • 现在可以定制滚动时应该显示的图片,感谢 ac1dpax。例如

    LCBannerView *bannerView = [[LCBannerView alloc] initWithFrame:CGRectMake(0, 20.0f, [UIScreen mainScreen].bounds.size.width, 200.0f)
                                                          delegate:self
                                                         imageName:@"banner"
                                                             count:3
                                                     timerInterval:3.0f
                                     currentPageIndicatorTintColor:[UIColor orangeColor]
                                            pageIndicatorTintColor:[UIColor whiteColor]];
    bannerView.pageDistance = 20.0f;
    bannerView.notScrolling = YES; // THIS LINE ⬅️
    bannerView;

版本 1.1.0

  • 现在可以自定义页面控制底部的距离。例如

    // ...
    bannerView.pageDistance = 20.0f;

版本 1.0.0

  • 初始提交。

感谢

支持

许可

MIT 许可证