寫一款廣泛知足 95% 需求的分頁控制器;以極少的學習成本進行擴展,以知足100%需求的分頁控制器,拿來即用,剩餘時間只需開心吃雞😎!git
核心代碼不足千行,有興趣請移步github
CD_PageControl 很是簡單的代碼實現強大的功能bash
public class CD_PageControl<Item: CD_PageControlItemProtocol, Buoy:CD_PageControlBuoyProtocol>: UIView where Item: UIView, Buoy: UIView {
...
}
複製代碼
CD_PageControl 包含兩項內容:標籤 Item 、浮漂 Buoy; Item 與 Buoy 均可以自定義,自定義的 Item、Buoy 分別遵循 CD_PageControlItemProtocol 、CD_PageControlBuoyProtocol 以得到相關數據服務app
CD_PageControl 能力在於導航標籤與浮漂簡單輕鬆的自定義、可實現市面上如:淘寶、京東、商品詳情頁、優酷、愛奇藝、今日頭條、汽車之家.....你想實現的分頁導航樣式ide
lazy var pageControl: CD_PageControl = {
return CD_PageControl<CD_PageControlItem,CD_PageControlBuoy>(itemConfig:CD_PageControlItem.Model(), buoyConfig: CD_PageControlBuoy.Model())
}()
pageControl.dataSource = (0..<3).map({ (i) -> CD_PageControlItemDataSource in
var d = CD_PageControlItemDataSource()
d.id = i.stringValue
d.title = "Title-\(i)"
return d
})
複製代碼
CD_PageViewController / CD_PageView 數據源 dataSource 分別對應 UIViewController / UIView 基於 CD_Form 排版組件 遵循 CD_RowVCProtocol / CD_RowViewProtocol 協議,經過 CD_RowVC / CD_RowView 構建佈局
public var dataSource:[CD_RowViewProtocol] = [] {
didSet{
updateViewControllers()
reloadData()
}
}
複製代碼
lazy var pageVC: CD_PageViewController = {
return CD_PageViewController()
}()
pageVC.dataSource = [CD_RowVC<VC_PageA>(dataSource: "id", config: "config"),
CD_RowVC<VC_PageB>(),
CD_RowVC<VC_PageC>()]
pageVC.dataSource.append(CD_RowVC<VC_PageA>())
pageVC.dataSource += [CD_RowVC<VC_PageA>()]
pageVC.selectIndex = 2
複製代碼
子頁面控制器 遵循 CD_UIViewControllerProtocol 得到數據服務學習
extension VC_PageA: CD_UIViewControllerProtocol {
static func row_init(withDataSource dataSource: Any?, config: Any?, callBack: CD_RowCallBack?, tapBlock: CD_RowDidSelectBlock?) -> UIViewController {
let vc = VC_PageA.show()
vc.dataSource = dataSource
vc.config = config
return vc
}
typealias DataSource = Any
typealias ConfigModel = Any
var config: ConfigModel? {
get { return nil }
set {}
}
var dataSource: DataSource? {
get { return nil }
set {}
}
}
複製代碼