- A View Can Infinite Loop Scroll.
Use the CocoaPods.
In your Podfile
pod 'SCLoopScrollView'
Get SCNumberKeyBoard
#import "SCLoopScrollView.h"
Drag SCLoopScrollViewDemo/Classes
folder into your project
#import "SCLoopScrollView.h"
NSArray *images = @[@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/1.imageset/1%402x.png",
[UIImage imageNamed:@"3"],
@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/2.imageset/2%402x.png",
[UIImage imageNamed:@"4"],
@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/5.imageset/5%402x.png"];
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 = @[@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/1.imageset/1%402x.png",
[UIImage imageNamed:@"3"],
@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/2.imageset/2%402x.png",
[UIImage imageNamed:@"4"],
@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/5.imageset/5%402x.png"];
_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中使用。
- 只需要简单的设置一下图片源既可以,三行代码搞定无限循环广告视图。
- 目前图片源支持图片链接和UIImage实例。
- cocoapods导入:
pod 'SCLoopScrollView'
- 手动导入:
- 将
SCLoopScrollViewDemo/Classes
文件夹中的所有文件拽入项目中 - 导入主头文件:
#import "SCLoopScrollView.h"
NSArray *images = @[@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/1.imageset/1%402x.png",
[UIImage imageNamed:@"3"],
@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/2.imageset/2%402x.png",
[UIImage imageNamed:@"4"],
@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/5.imageset/5%402x.png"];
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 = @[@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/1.imageset/1%402x.png",
[UIImage imageNamed:@"3"],
@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/2.imageset/2%402x.png",
[UIImage imageNamed:@"4"],
@"https://raw.githubusercontent.com/shicang1990/SCLoopScrollView/master/Images.xcassets/5.imageset/5%402x.png"];
_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;
}];