最近比較有時間,把之前項目自己寫的一個輪播圖整理一下,封裝起來。
該庫支持網絡圖片和本地圖片展示,同時也支持代碼創建和xib創建。
該庫需要用到SDWebImage對圖片進行下載緩存操作,所以需要集成SDWebImage第三方庫
將庫中的HCCycleView文件夾拖入你的文件後即可使用
在使用的地方引入“HCCycleView.h”
HCCycleView *cycleScrollView = [HCCycleView cycleViewWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 205) delegate:self placeholderImage:PLACEHOLDER_IMAGE];
xib 創建方式
先拖入一個UIView控件將UIView的類設置成HCCycleView
將該View拖線到你要使用的控制器裡
// 是否自動輪播
@property (nonatomic,assign) BOOL isAutoScroll;
// 自動輪播的時間間隔
@property (nonatomic,assign) NSTimeInterval timerInterVal;
// 圖片占位圖
@property (nonatomic,strong) UIImage *placeholderImage;
/*** 圖片數組 */
@property (nonatomic,copy) NSArray *imageArrays;
// pageControl類型
@property (nonatomic,assign) HCPageControlType pageControlType;
// pageControl的顯示位置
@property (nonatomic,assign) HCPageControlPosition pageControlPosition;
// pageControl的dot之間間隔大小
@property (nonatomic,assign) CGFloat pageControlDotInterSpace;
// pageControl的dot的大小
@property (nonatomic,assign) CGSize pageControlDotSize;
// pageControl的dot的邊框寬度
@property (nonatomic,assign) CGFloat pageControlDotBorderWidth;
// pageControl的自定義frame
@property (nonatomic,assign) CGRect pageControlCustomFrame;
// pageControl距離底部的距離
@property (nonatomic,assign) CGFloat pageControlBottom;
// pageControl的pageControlColor
@property (nonatomic,strong) UIColor *pageControlColor;
// pageControl的currentPageControlColor
@property (nonatomic,strong) UIColor *currentPageControlColor;
/*** 推薦初始化方法 */
+ (instancetype)cycleViewWithFrame:(CGRect)frame delegate:(id <HCCycleViewDelegate>)delegate placeholderImage:(UIImage *)placeholderImage;
/*** 點擊圖片Block */
@property (nonatomic,copy) void (^didClickPicture)(NSInteger);
/*** 滾動到某一頁方法 (從0開始算起) */
- (void)scrollToIndex:(NSInteger)index animate:(BOOL)animate;
// 圖片 本地圖片和網絡圖片均支持
NSArray *imageArr = @[@"http://image72.360doc.com/DownloadImg/2014/04/2301/40991904_7.jpg",
@"http://img4.duitang.com/uploads/blog/201406/28/20140628174102_R8Hhd.thumb.700_0.jpeg",
[UIImage imageNamed:@"local_image.jpg"],
@"http://uploadfile.bizhizu.cn/2014/0507/20140507103639644.jpg",
@"http://image55.360doc.com/DownloadImg/2012/10/2517/27773420_5.jpg",
@"http://pic62.nipic.com/file/20150303/17961491_092446597000_2.jpg"
];
HCCycleView *cycleScrollView = [HCCycleView cycleViewWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 205) delegate:self placeholderImage:PLACEHOLDER_IMAGE];
cycleScrollView.isAutoScroll = NO;
cycleScrollView.currentPageControlColor = [UIColor whiteColor];
cycleScrollView.pageControlColor = [UIColor purpleColor];
cycleScrollView.pageControlType = HCPageControlTypeBorder;
// cycleScrollView.pageControlPosition = HCPageControlPositionRight;
cycleScrollView.pageControlCustomFrame = CGRectMake(10, 180, 100, 20);
cycleScrollView.pageControlDotBorderWidth = 1;
cycleScrollView.pageControlDotInterSpace = 20;
cycleScrollView.pageControlDotSize = CGSizeMake(10, 10);
cycleScrollView.imageArrays = imageArr;
[self.view addSubview:cycleScrollView];
// 圖片 本地圖片和網絡圖片均支持
NSArray *imageArr = @[@"http://image72.360doc.com/DownloadImg/2014/04/2301/40991904_7.jpg",
@"http://img4.duitang.com/uploads/blog/201406/28/20140628174102_R8Hhd.thumb.700_0.jpeg",
[UIImage imageNamed:@"local_image.jpg"],
@"http://uploadfile.bizhizu.cn/2014/0507/20140507103639644.jpg",
@"http://image55.360doc.com/DownloadImg/2012/10/2517/27773420_5.jpg",
@"http://pic62.nipic.com/file/20150303/17961491_092446597000_2.jpg"
];
// xib創建
self.cycleView.isAutoScroll = YES;
self.cycleView.delegate = self;
self.cycleView.timerInterVal = 5;
self.cycleView.placeholderImage = PLACEHOLDER_IMAGE;
self.cycleView.pageControlType = HCPageControlTypeNone;
self.cycleView.currentPageControlColor = [UIColor whiteColor];
self.cycleView.pageControlColor = [UIColor purpleColor];
self.cycleView.pageControlPosition = HCPageControlPositionMiddle;
self.cycleView.imageArrays = imageArr;
如果需要看詳細的代碼,可以到我的github上去看,這裡就不一一貼出來了。
github地址:https://github.com/ACoderNHC/HCCycleView