swift版本的帶進度的無限輪播頭部bar。
HRCycleView基于UICollectionView來實現浇辜。
功能包含:
- 支持單張圖片
- 支持帶進度條樣式
- 支持持續(xù)時間自定義
- 支持本地圖片顯示旷余,網路圖顯示,本地圖片和網路圖混合顯示
- 支持自定義圖片展示Cell(純代碼和Xib創(chuàng)建都支持)
- 支持UIPageControl具體位置設置
- 支持UIPageControl顯示顏色設置
- 支持圖片點擊回調
cocopod
pod 'HRCycleView'
本地圖片滾動視圖
/// 本地圖片
let carouselView = CarouselView(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: vMain.frame.height),
["img1.jpg","img2.jpg","img3.jpg","img4.jpg"],
placeholderImage: UIImage.creatImageWithColor(color: .black),
pageLocation: .CenterBottom(bottom: 12),
autoScrollDelay: 3)
carouselView.pageIndicatorTintColor = .blue
carouselView.delegate = self
vMain.addSubview(carouselView)
網絡圖片滾動視圖
let carouselView2 = CarouselView(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: vMain.frame.height),
picUrl,
placeholderImage: UIImage(named: "img1.jpg")!,
pageLocation: .LeftBottom(leading: 15, bottom: 15),
autoScrollDelay: 5)
carouselView2.pageIndicatorTintColor = .orange
carouselView2.delegate = self
vMain2.addSubview(carouselView2)
自定義cell滾動視圖
let carouselView3 = CarouselView(CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: vMain.frame.height),
picUrl,
placeholderImage: UIImage(named: "img1.jpg")!,
pageLocation: .RightBottom(trailing: 15, bottom: 15),
autoScrollDelay: 3)
carouselView3.pageIndicatorTintColor = .green
carouselView3.delegate = self
carouselView3.register([UINib.init(nibName: "CustomCollectionViewCell", bundle: nil)], identifiers: ["CustomCollectionViewCell"])
vMain3.addSubview(carouselView3)
// 自定義Cell-Delegate-(純代碼和Xib創(chuàng)建都支持)
func carouselView(carouselView: CarouselView, collectionView: UICollectionView, cellForItemAt indexPath: IndexPath, picture: String) -> UICollectionViewCell? {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCollectionViewCell", for: indexPath) as! CustomCollectionViewCell
cell.lable.text = "自定義Cell\n第 \(indexPath.item) 項"
cell.image.kf.setImage(with: URL(string: picture))
return cell
}
點擊代理回調
func carouselView(carouselView: CarouselView, didSelectItemAt index: Int) {
print("\(index)巴拉巴拉")
}