相信大家在應(yīng)用中經(jīng)常會(huì)看到輪播圖,這一炫酷的效果實(shí)現(xiàn)起來確實(shí)是一件不是很輕松的事情校仑。今天筆者向大家推薦一款封裝好的源碼,分分鐘就可以搞定,是不是很神奇。
接下來看如何實(shí)現(xiàn)它?
首先可以參考ImageLoopDemo點(diǎn)擊下載,將HADirect引入工程,導(dǎo)入#import "HADirect.h"頭文件,即可調(diào)用方法實(shí)現(xiàn):
#import <UIKit/UIKit.h>
#import "UIImageView+WebCache.h"
typedef void(^imageClickBlock)(NSInteger index);
@interface HADirect : UIView
//輪播的ScrollView
@property(strong,nonatomic) UIScrollView *direct;
//輪播的頁碼
@property(strong,nonatomic) UIPageControl *pageVC;
//輪播滾動(dòng)時(shí)間間隔
@property(assign,nonatomic) CGFloat time;
//初始化圖片格式的HADirect
+(instancetype)direcWithtFrame:(CGRect)frame ImageArr:(NSArray *)imageNameArray AndImageClickBlock:(imageClickBlock)clickBlock;
//初始化自定義樣式的HADirect
+(instancetype)direcWithtFrame:(CGRect)frame ViewArr:(NSArray *)customViewArr AndClickBlock:(imageClickBlock)clickBlock;
//開始定時(shí)器
-(void)beginTimer;
//銷毀定時(shí)器
-(void)stopTimer;
@end
1.初始化圖片格式輪播
+(instancetype)direcWithtFrame:(CGRect)frame ImageArr:(NSArray *)imageNameArray AndImageClickBlock:(imageClickBlock)clickBlock;
// imageNameArray放置圖片名字的數(shù)組即可
2.自定義視圖輪播
+(instancetype)direcWithtFrame:(CGRect)frame ViewArr:(NSArray *)customViewArr AndClickBlock:(imageClickBlock)clickBlock;
//customViewArr放置自定義視圖所組成的數(shù)組
代碼示例:
NSArray *images = @[@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg"];
HADirect *direct = [HADirect direcWithtFrame:CGRectMake(0, 20, SCREENWIDTH, 250) ImageArr:images AndImageClickBlock:nil];
[self.view addSubview:direct];