CocoaPods安裝
pod 'PGBanner'
pod update
複製程式碼
使用
1、無限圖片輪播
PGBanner *banner = [[PGBanner alloc]initImageViewWithFrame:self.topView.bounds imageList:@[@"photo1", @"photo2", @"photo3"] timeInterval:3.0];
banner.delegate = self;
[self.view addSubview:banner];
#pragma mark - PGBannerDelegate
- (void)selectAction:(NSInteger)didSelectAtIndex didSelectView:(id)view {
NSLog(@"index = %ld view = %@", didSelectAtIndex, view);
}
複製程式碼
2、自定義控制元件無限輪播
使用自定義控制元件輪播時,需要注意兩點
1、一定要把需要輪播的第一個view放到陣列的最後位置
2、一定要把需要輪播的最後一個view放到陣列的第一個位置
CustomView *view1 = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil].firstObject;
view1.index = 0;
CustomView *view2 = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil].firstObject;
view2.index = 1;
CustomView *view3 = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil].firstObject;
view3.index = 2;
//將最後一個view放到陣列的第一個位置
CustomView *view0 = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil].firstObject;
view0.index = 2;
//將第一個view放到陣列的第最後位置
CustomView *view4 = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil].firstObject;
view4.index = 0;
PGBanner *banner = [[PGBanner alloc]initViewWithFrame:self.topView.bounds ViewList:@[view0, view1, view2, view3, view4] timeInterval:3.0];
banner.delegate = self;
[self.view addSubview:banner];
#pragma mark - PGBannerDelegate
- (void)selectAction:(NSInteger)didSelectAtIndex didSelectView:(id)view {
NSLog(@"index = %ld view = %@", didSelectAtIndex, view);
}
複製程式碼
GitHub地址
https://github.com/xiaozhuxiong121/PGBanner
#Swift版的地址 https://github.com/xiaozhuxiong121/PGBannerSwift