美文网首页征服iOS程序员
【iOS】自定义控件无限轮播 + 无限图片轮播

【iOS】自定义控件无限轮播 + 无限图片轮播

作者: piggybear | 来源:发表于2017-07-05 17:38 被阅读198次
PGBanner.gif

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

相关文章

网友评论

    本文标题:【iOS】自定义控件无限轮播 + 无限图片轮播

    本文链接:https://www.haomeiwen.com/subject/usiqhxtx.html