CJCarouselView
示例
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
。
要求
安装
CJCarouselView 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中
pod 'CJCarouselView'
基本用法
- 初始化
- (CJCarouselView *)carouselView {
if (_carouselView == nil) {
CJCarouselView *aView = [[CJCarouselView alloc] init];
aView.dataSource = self;
aView.delegate = self;
aView.fadeoutAlpha = 0.2;
aView.enableScrollOnSinglePage = YES;
[aView smartUpdateLayoutInsetForPrePageExposed:30 nextPageExposed:30 pageGap:20];
_carouselView = aView;
}
return _carouselView;
}
- (void)viewControllerReloadData {
self.imageUrls = @[
@"https://uploadbeta.com/api/pictures/random/?i=0",
@"https://uploadbeta.com/api/pictures/random/?i=1",
@"https://uploadbeta.com/api/pictures/random/?i=2",
@"https://uploadbeta.com/api/pictures/random/?i=3",
@"https://uploadbeta.com/api/pictures/random/?i=4",
@"https://uploadbeta.com/api/pictures/random/?i=5",
];
[self.carouselView reloadData];
}
- 实现数据源方法
- (NSUInteger)carouselViewNumberOfPages:(CJCarouselView *)pageView {
return [self.imageUrls isKindOfClass:[NSArray class]] ? self.imageUrls.count : 0;
}
- (CJCarouselViewPage *)carouselView:(CJCarouselView *)pageView pageViewAtIndex:(NSUInteger)index reuseableView:(CJCarouselViewPage *)reuseableView {
if (!reuseableView) {
reuseableView = [[CJCarouselViewPage alloc] init];
reuseableView.contentLabel.textColor = [UIColor whiteColor];
reuseableView.contentLabel.textAlignment = NSTextAlignmentCenter;
reuseableView.imageView.layer.cornerRadius = 8.f;
[reuseableView.imageView setContentMode:UIViewContentModeScaleAspectFill];
reuseableView.enableRippleHighlightStyle = YES;
}
[reuseableView.imageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrls[index]]];
reuseableView.contentLabel.text = [NSString stringWithFormat:@"%ld", index];
return reuseableView;
}
- 如有必要,实现代理方法
- (void)carouselView:(CJCarouselView *)carouselView didScrollToPageIndexRatio:(CGFloat)pageIndexRatio {
self.ratioIndicator.text = [NSString stringWithFormat:@"%.8f/%ld", pageIndexRatio + 1, carouselView.numberOfPages];
}
- (void)carouselView:(CJCarouselView *)carouselView didSelectPageAtIndex:(NSUInteger)index {
[self.view makeToast:[NSString stringWithFormat:@"Selected Page %ld", index]];
}
屏幕截图
作者
cj1024, [email protected]
许可证
CJCarouselView 库采用 MIT 许可证。更多详细信息请参阅 LICENSE 文件。