KJBannerView
- 介紹一下自己之前寫的無限輪播圖庫峭梳,無限自動循環(huán)滾動,大家有什么需求可以給我留言苏潜,持續(xù)更新中...
Demo地址:KJBannerViewDemo
功能介紹
KJBannerView 是一款輪播Banner,支持動態(tài)圖和網(wǎng)圖混播
1魁瞪、縮放無限自動循環(huán)滾動 √
2、支持四種方向滾動驳概,從左往右顺又、從右往左稚照、從上往下果录、從下往上 √
3弱恒、自定義繼承斤彼,定制不同樣式蘸泻,詳情使用請見Demo √
4悦施、支持網(wǎng)絡(luò)動態(tài)圖和網(wǎng)絡(luò)圖片和本地圖片混合輪播 √
5抡诞、支持在Storyboard和Xib中創(chuàng)建并配置其屬性 √
6昼汗、提供多種分頁控件PageControl顯示 √
7顷窒、自帶緩存加載,內(nèi)部封裝網(wǎng)圖下載緩存工具 √
使用方法
pod 'KJBannerView' # 輪播圖
API & Property
NS_ASSUME_NONNULL_BEGIN
IB_DESIGNABLE
@interface KJBannerView : UIView
/// 代理方法
@property (nonatomic,weak) id<KJBannerViewDelegate> delegate;
@property (nonatomic,weak) id<KJBannerViewDataSource> dataSource;
/// Block回調(diào)
@property (nonatomic,readwrite,copy) void(^kSelectBlock)(KJBannerView *banner, NSInteger idx);
@property (nonatomic,readwrite,copy) void(^kScrollBlock)(KJBannerView *banner, NSInteger idx);
/// 暫停計時器滾動處理,備注:在viewDidDisappear當(dāng)中實現(xiàn)
- (void)kj_pauseTimer;
/// 繼續(xù)計時器滾動坛掠,備注:在viewDidAppear當(dāng)中實現(xiàn)
- (void)kj_repauseTimer;
/// 滾動到指定位置屉栓,備注:需要在設(shè)置數(shù)據(jù)源之后調(diào)用
- (void)kj_makeScrollToIndex:(NSInteger)index;
/// 使用Masonry自動布局友多,請在設(shè)置布局之后調(diào)用該方法
- (void)kj_useMasonry;
//************************ 數(shù)據(jù)源API ************************
/// 數(shù)據(jù)源
@property (nonatomic,strong) NSArray<NSString*>*imageDatas;
/// 自動滾動間隔時間欠拾,默認2s
@property (nonatomic,assign) IBInspectable CGFloat autoTime;
/// 是否無線循環(huán)藐窄,默認yes
@property (nonatomic,assign) IBInspectable BOOL infiniteLoop;
/// 是否自動滑動荆忍,默認yes
@property (nonatomic,assign) IBInspectable BOOL autoScroll;
/// 是否縮放刹枉,默認不縮放
@property (nonatomic,assign) IBInspectable BOOL isZoom;
/// cell寬度微宝,左右寬度
@property (nonatomic,assign) IBInspectable CGFloat itemWidth;
/// cell間距,默認為0
@property (nonatomic,assign) IBInspectable CGFloat itemSpace;
/// 是否顯示分頁控件镶摘,默認yes
@property (nonatomic,assign) IBInspectable BOOL showPageControl;
/// 滾動方向凄敢,默認從右到左
@property (nonatomic,assign) KJBannerViewRollDirectionType rollType;
/// 分頁控制器
@property (nonatomic,strong,readonly) KJPageView *pageControl;
//************************ 廢棄屬性方法 *****************************/
/// 支持自定義Cell涝缝,自定義Cell需繼承自 KJBannerViewCell
@property (nonatomic,strong) Class itemClass DEPRECATED_MSG_ATTRIBUTE("Please use dataSource [kj_BannerView:BannerViewCell:ImageDatas:Index:]");
@end
//******************** 自帶KJBannerViewCell可設(shè)置屬性 ********************
@interface KJBannerView (KJBannerViewCell)
/// 是否裁剪嫩挤,默認NO
@property (nonatomic,assign) IBInspectable BOOL bannerScale;
/// imagView圓角消恍,默認為0px
@property (nonatomic,assign) IBInspectable CGFloat bannerRadius;
/// cell的占位圖约啊,用于網(wǎng)絡(luò)未加載到圖片時
@property (nonatomic,strong) IBInspectable UIImage *placeholderImage;
/// 輪播圖片的ContentMode恰矩,默認為 UIViewContentModeScaleToFill
@property (nonatomic,assign) UIViewContentMode bannerContentMode;
/// 圖片的樣式外傅,默認 KJBannerViewImageTypeNetIamge 網(wǎng)絡(luò)圖片
@property (nonatomic,assign) KJBannerViewImageType imageType;
/// 是否采用動態(tài)圖緩存萎胰,默認NO
@property (nonatomic,assign) BOOL openGIFCache;
@end
NS_ASSUME_NONNULL_END
KJBannerView類介紹
Class | 功能區(qū) |
---|---|
KJBannerView | 輪播圖主控件 |
KJPageView | 自定義分頁控件 |
KJBannerViewFlowLayout | Cell縮放管理 |
KJBannerViewCell | 基類,自定義需繼承該Cell |
KJBannerDatasInfo | 自帶BannerViewCell數(shù)據(jù)模型 |
KJLoadImageView | 不依賴三方網(wǎng)絡(luò)加載圖片顯示控件 |
KJBannerTool | 工具方法 |
KJBannerViewType | 枚舉文件夾 |
KJBannerViewProtocol | 委托協(xié)議相關(guān) |
NSTimer+KJSolve | 計時器分類 |
UIImage+KJBannerGIF | 動態(tài)圖分類 |
KJBannerViewCacheManager | 緩存工具 |
KJBannerViewDownloader | 網(wǎng)絡(luò)請求工具 |
KJBannerViewLoadManager | 網(wǎng)圖下載工具 |
支持Xib快捷設(shè)置屬性
效果圖
下載測試效果圖搓扯,圖片采用信號量方式獲取
用法示例
Masonry自動布局
使用Masonry自動布局,請在設(shè)置布局之后調(diào)用該方法kj_useMasonry
- (void)setMasonry{
self.banner2 = [[KJBannerView alloc]init];
self.banner2.autoTime = 2;
self.banner2.isZoom = YES;
self.banner2.itemSpace = -10;
self.banner2.itemWidth = 280;
self.banner2.delegate = self;
self.banner2.dataSource = self;
self.banner2.imageType = KJBannerViewImageTypeMix;
self.banner2.pageControl.pageType = PageControlStyleSizeDot;
self.banner2.pageControl.displayType = KJPageControlDisplayTypeRight;
self.banner2.pageControl.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
[self.backView addSubview:self.banner2];
[self.banner2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.bottom.mas_equalTo(0);
}];
[self.banner2 kj_useMasonry];
self.banner2.imageDatas = self.temp;
}
Xib布局
- (void)setXib{
self.banner.delegate = self;
self.banner.pageControl.pageType = PageControlStyleRectangle;
self.banner.pageControl.selectColor = UIColor.greenColor;
self.banner.pageControl.dotwidth = 20;
self.banner.pageControl.dotheight = 2;
self.banner.pageControl.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
self.banner.pageControl.displayType = KJPageControlDisplayTypeLeft;
self.banner.imageType = KJBannerViewImageTypeMix;
self.banner.bannerScale = YES;
self.banner.rollType = KJBannerViewRollDirectionTypeBottomToTop;
self.banner.bannerContentMode = UIViewContentModeScaleAspectFill;
self.banner.imageDatas = @[tu2,gif2,@"IMG_0139",@"tu3"];
[self.banner kj_makeScrollToIndex:1];
}
委托自定義控件
#pragma mark - KJBannerViewDataSource
- (UIView*)kj_BannerView:(KJBannerView*)banner BannerViewCell:(KJBannerViewCell*)bannercell ImageDatas:(NSArray*)imageDatas Index:(NSInteger)index{
KJBannerModel *model = imageDatas[index];
CGRect rect = {0, 0, 100, 20};
UILabel *label = [[UILabel alloc]initWithFrame:rect];
if (index == 0) {
label.text = @"定制不同的控件";
label.frame = CGRectMake(0, 0, bannercell.contentView.frame.size.width, 40);
label.font = [UIFont boldSystemFontOfSize:35];
label.textColor = UIColor.greenColor;
label.textAlignment = NSTextAlignmentCenter;
}
KJLoadImageView *imageView = [[KJLoadImageView alloc]initWithFrame:bannercell.contentView.bounds];
imageView.kj_isScale = YES;
[imageView kj_setImageWithURLString:model.customImageUrl Placeholder:[UIImage imageNamed:@"tu3"]];
[imageView addSubview:label];
return imageView;
}
繼承方式自定義控件
- (void)setText{
self.banner3.showPageControl = NO;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
self.banner3.itemClass = [KJCollectionViewCell class];
#pragma clang diagnostic pop
self.banner3.rollType = KJBannerViewRollDirectionTypeBottomToTop;
self.banner3.imageDatas = @[@"測試文本滾動",@"覺得好用請給我點個星",@"有什么問題也可以聯(lián)系我",@"郵箱: ykj310@126.com"];
}
自定義Cell使用
- (void)setModel:(NSObject*)model{
self.label.text = (NSString*)model;
}