pod 'SBCycleScrollView','~> 0.0.8'git
Github地址,歡迎star😆github
使用cocoapods導入,pod 'SBCycleScrollView','~>0.0.4',若是發現pod search SBCycleScrollView 搜索出來的不是最新版本,請先執行pod setup指令,獲取最新數據源就能夠了.swift
經過網絡圖片地址初始化
let cycleScrollView = CycleScrollView.initScrollView(frame: frame, imageNamesGroup: imageUrls, cycleOption: CycleOption())
複製代碼
經過本地圖片名稱或地址初始化
let cycleScrollView = CycleScrollView.initScrollView(frame: frame, imageNamesGroup: localImages, cycleOptions: CycleOptions())
複製代碼
經過文字數組初始化
let cycleScrollView = CycleScrollView.initScrollView(frame: frame, titleGroup: titles, cycleOption: CycleOption())
複製代碼
推薦方式,經過代理和佔位圖初始化,經常使用於圖片異步獲取的時候
let cycleScrollView = CycleScrollView.initScrollView(frame: frame, delegate: self, placehoder: UIImage.init(named: "place.png"), cycleOptions: CycleOptions())
cycleScrollView.imageURLStringsGroup = imageUrls
複製代碼
import UIKit
public enum PageControlStyle {
case classic,aji,aleppo,chimayo,jalapeno,jaloro,paprika,puya
}
public enum PageControlAliment {
case center,right
}
public struct CycleOption {
public var scrollDirection:UICollectionViewScrollDirection = UICollectionViewScrollDirection.horizontal
public var showPageControl: Bool = true//是否顯示pageControl,默認顯示
public var isOnlyDisplayText: Bool = false//只顯示文字,默認false
public var imageViewMode: UIViewContentMode = UIViewContentMode.scaleToFill //圖片填充樣式,默認fill
public var scrollTimeInterval: TimeInterval = 2.0//滑動間隔時間
public var titleLabelBackgroundColor: UIColor = .init(red: 0, green: 0, blue: 0, alpha: 0.2)//label背景顏色
public var textColor: UIColor = .white//文字顏色
public var textFont: UIFont = UIFont.systemFont(ofSize: 14)//文字字體大小
public var titleLabelHeight: CGFloat = 30//label高度,默認30
public var textAlignment: NSTextAlignment = NSTextAlignment.left//文字默認居左
public var numberOfline = 1 // 文字行數,默認一行
public var radius: CGFloat = 5//pageControl圓點半徑
public var pageAliment: PageControlAliment = PageControlAliment.center//pageControl位置,默認居中
public var bottomOffset: CGFloat = 0//pageControl距離底部距離
public var rightOffset: CGFloat = 0//pageControl距離右側距離
public var padding: CGFloat = 7 //pagecontol間距
public var pageStyle: PageControlStyle = PageControlStyle.classic//pageControl樣式,默認系統樣式
public var currentPageDotColor: UIColor = .white//當前pageControl圓點的顏色
public var pageDotColor: UIColor = .gray//其餘pageControl圓點的顏色
}
複製代碼
代理名稱SBCycleScrollViewDelegate,代理方法數組
func didSelectedCycleScrollView(_ cycleScrollView: SBCycleScrollView, _ Index: NSInteger) {
print("點擊了第\(Index)張圖片")
}
複製代碼
####修改配置屬性,達到你想要的效果bash
\\先配置再初始化
var option = CycleOption()
option.currentPageDotColor = .blue
option.radius = 10
option.pageStyle = PageControlStyle.jalapeno
let cycleScrollView = CycleScrollView.initScrollView(frame: view.frame, imageURLsGroup: imageUrls, cycleOption: option)
\\初始化後再修改配置
let cycleScrollView = CycleScrollView.initScrollView(frame: view.frame, imageURLsGroup: imageUrls, cycleOption: CycleOption())
var option = CycleOption()
option.currentPageDotColor = .blue
option.radius = 10
option.pageStyle = PageControlStyle.jalapeno
cycleScrollView.option = option
複製代碼
####點擊圖片代理 代理名稱SBCycleScrollViewDelegate,代理方法網絡
func didSelectedCycleScrollView(_ cycleScrollView: CycleScrollView, _ Index: NSInteger) {
print("點擊了第\(Index)張圖片")
}
複製代碼