SCLoopScrollView 0.6

SCLoopScrollView 0.6

测试测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年1月

Andy维护。




  • ShiCang
  • 一个视图可以无限循环滚动。

安装

使用CocoaPods

在您的Podfile中

pod 'SCLoopScrollView'

获取SCNumberKeyBoard

#import "SCLoopScrollView.h"

或者

SCLoopScrollViewDemo/Classes文件夹拖入您的项目中

#import "SCLoopScrollView.h"

预览

如何使用

自行初始化

NSArray *images = @[@"http://i8.tietuku.com/a6542887e864efc0.jpg",
                    [UIImage imageNamed:@"3"],
                    @"http://i8.tietuku.com/5730f7ebadae2c41.jpg",
                    [UIImage imageNamed:@"4"],
                    @"http://i8.tietuku.com/149caebe062fc98c.jpg"];

SCLoopScrollView *scrollView = [[SCLoopScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.width*0.75)];
scrollView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:scrollView];
scrollView.dataSource = images;
[scrollView show:^(NSInteger index) {
    NSLog(@"Tap Index:%@", @(index));
} scrolled:^(NSInteger index) {
    NSLog(@"Current Index:%@", @(index));
}];

通过故事板初始化

NSArray *images = @[@"http://i8.tietuku.com/a6542887e864efc0.jpg",
                    [UIImage imageNamed:@"3"],
                    @"http://i8.tietuku.com/5730f7ebadae2c41.jpg",
                    [UIImage imageNamed:@"4"],
                    @"http://i8.tietuku.com/149caebe062fc98c.jpg"];

_scrollView.dataSource = images;

__weak __typeof__(self)weakSelf = self;
[_scrollView show:^(NSInteger index) {
    __strong __typeof__(self)strongSelf = weakSelf;
    strongSelf.tapLabel.text = @(index).stringValue;
} scrolled:^(NSInteger index) {
    __strong __typeof__(self)strongSelf = weakSelf;
    strongSelf.indexLabel.text = @(index).stringValue;
}];

无限循环滚动视图

  • 可以同时在代码、Xib和Storyboard中使用。
  • 只需简单设置图片源即可,三行代码搞定无限循环广告视图。
  • 目前图像源支持图片链接和UIImagePickerController实例。

如何使用SCLoopScrollView

  • cocoapods导入:pod 'SCLoopScrollView'
  • 手动导入:
  • SCLoopScrollViewDemo/Classes文件夹中的所有文件拖入项目中
  • 导入主头文件:#import "SCLoopScrollView.h"

效果图

代码

手动编码

NSArray *images = @[@"http://i8.tietuku.com/a6542887e864efc0.jpg",
                    [UIImage imageNamed:@"3"],
                    @"http://i8.tietuku.com/5730f7ebadae2c41.jpg",
                    [UIImage imageNamed:@"4"],
                    @"http://i8.tietuku.com/149caebe062fc98c.jpg"];

SCLoopScrollView *scrollView = [[SCLoopScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.width*0.75)];
scrollView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:scrollView];
scrollView.dataSource = images;
[scrollView show:^(NSInteger index) {
    NSLog(@"Tap Index:%@", @(index));
} scrolled:^(NSInteger index) {
    NSLog(@"Current Index:%@", @(index));
}];

通过故事板

NSArray *images = @[@"http://i8.tietuku.com/a6542887e864efc0.jpg",
                    [UIImage imageNamed:@"3"],
                    @"http://i8.tietuku.com/5730f7ebadae2c41.jpg",
                    [UIImage imageNamed:@"4"],
                    @"http://i8.tietuku.com/149caebe062fc98c.jpg"];

_scrollView.dataSource = images;

__weak __typeof__(self)weakSelf = self;
[_scrollView show:^(NSInteger index) {
    __strong __typeof__(self)strongSelf = weakSelf;
    strongSelf.tapLabel.text = @(index).stringValue;
} scrolled:^(NSInteger index) {
    __strong __typeof__(self)strongSelf = weakSelf;
    strongSelf.indexLabel.text = @(index).stringValue;
}];