iOS 輪播圖 YJBannerView 的使用方法詳解
阿新 • • 發佈:2018-12-22
YJBannerView
- 使用簡單、功能豐富的
Objective-C版
輪播控制元件, 基於UICollectionView
實現, 多種場景均支援使用.
效果樣例
Features
- [x] 支援自帶PageControl樣式配置, 也支援自定義
- [x] 支援上、下、左、右四個方向自動、手動動滾動
- [x] 支援自動滾動時間設定
- [x] 支援首尾迴圈滾動的開關
- [x] 支援滾動相關手勢的開關
- [x] 支援ContentMode的設定
- [x] 支援Banner標題的設定自定義
- [x] 支援自定義UICollectionViewCell
- [x] 支援自定義 UIView 填充BannerView
- [x] 支援在Storyboard\xib中建立並配置其屬性
- [x] 支援非首尾迴圈的Footer樣式和進入詳情回撥
- [x] 不依賴其他三方SDWebImage或者AFNetworking設定圖片
- [x] 支援CocoaPods
- [x] 支援Carthage
Installation
Cocoapods
YJBannerView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'YJBannerView'
Carthage
github "stackhou/YJBannerViewOC"
Usage
1.建立BannerView:
-(YJBannerView *)normalBannerView{
if (!_normalBannerView) {
_normalBannerView = [YJBannerView bannerViewWithFrame: CGRectMake(0, 20, kSCREEN_WIDTH, 180) dataSource:self delegate:self placeholderImageName:@"placeholder" selectorString:@"sd_setImageWithURL:placeholderImage:"];
_normalBannerView.pageControlAliment = PageControlAlimentRight;
_normalBannerView.autoDuration = 2.5f;
}
return _normalBannerView;
}
2.實現資料來源方法和代理:
// 將網路圖片或者本地圖片 或者混合陣列
- (NSArray *)bannerViewImages:(YJBannerView *)bannerView{
return self.imageDataSources;
}
// 將標題對應陣列傳遞給bannerView 如果不需要, 可以不實現該方法
- (NSArray *)bannerViewTitles:(YJBannerView *)bannerView{
return self.titlesDataSources;
}
// 代理方法 點選了哪個bannerView 的 第幾個元素
-(void)bannerView:(YJBannerView *)bannerView didSelectItemAtIndex:(NSInteger)index{
NSString *title = [self.titlesDataSources objectAtIndex:index];
NSLog(@"當前%@-->%@", bannerView, title);
}
擴充套件自定義方法
// 自定義Cell方法
- (Class)bannerViewCustomCellClass:(YJBannerView *)bannerView{
return [HeadLinesCell class];
}
// 自定義Cell的資料重新整理方法
- (void)bannerView:(YJBannerView *)bannerView customCell:(UICollectionViewCell *)customCell index:(NSInteger)index{
HeadLinesCell *cell = (HeadLinesCell *)customCell;
[cell cellWithHeadHotLineCellData:@"打折活動開始了~~快來搶購啊"];
}
版本記錄
- 2015/5/10 版本1.0 生成靜態庫.a的方式,使用 Cocoapods 匯入
- 2016/10/17 版本2.0 原始碼的方式使用 Cocoapods 匯入
- 2017/5/29 版本2.1 預設自動滾動時間間隔調整為3s、動畫變化比例調整為1.0、設定標題預設 邊間距為10, 可任意設定, 支援Carthage
- 2017/7/3 版本2.1.1 通過傳遞UIImageView設定網路圖片的方法給BannerView設定圖片, 不再 依賴其他三方庫,如: SDWebImage
- 2017/7/14 版本2.1.4 程式碼功能及結構優化
- 2017/7/21 版本2.1.5 程式碼功能優化
- 2017/7/25 版本2.1.6 1.新增cycleScrollEnable控制是否需要首尾相連; 2.新增 bannerGestureEnable 手勢是否可用 3.新增bannerView:didScrollCurrentIndex:代理方法, 可以自定義PageControl
- 2017/7/28 版本2.1.7 1.新增FooterView 2.新增自定義View bannerView:viewForItemAtIndex: 方法
- 2017/7/30 版本2.2.0 調優、降低記憶體消耗
- 2017/8/21 版本2.2.1 當資料來源不為零時, 隱藏背景圖片
- 2017/9/25 版本2.2.2 當網路載入時間很長時 PlaceHolder 顯示優化