仿照有妖气的框架实践
效果实现

QQ20180813-101331.gif
基本框架布局

2DA436F667B040DAF973D688F2819614.png
第三方框架的使用

A9A8A9E24005C36A8FB6F0647310B1F0.png
一 、关于基础类的内容

4B0005334BFECC98BEA0ECAA6E625CD4.png
1.1上代码(关于BaseView)
Cell部分
import UIKit
import Reusable
// Mark 遵守Reusable协议
class BCBaseCollectionViewCell: UICollectionViewCell, Reusable {
override init(frame: CGRect) {
super.init(frame: frame)
configUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
open func configUI() {}
}
HeaderFooterView部分
import UIKit
class BCBaseTableViewHeaderFooterView: UITableViewHeaderFooterView, Reusable {
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
configUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
open func configUI() {}
}
以及另外的关于CollectonView的
注册阶段
lazy var vipColl: UICollectionView = {[weak self] in
let layout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 5
layout.minimumLineSpacing = 6
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
let width = floor((kScreenWidth - 10.0) / 3.0)
layout.itemSize = CGSize(width: width, height: 240)
let coll = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
coll.backgroundColor = UIColor(r: 242, g: 242, b: 242)
coll.register(cellType: BCComicCCell.self)
coll.register(supplementaryViewType: BCComicSeactionHeader.self, ofKind: UICollectionElementKindSectionHeader)
coll.register(supplementaryViewType: BCComicSeactionFoot.self, ofKind: UICollectionElementKindSectionFooter)
self?.bcTabView = coll
coll.bcFoot = BCRefreshTipKissFooter(with: "VIP用户专享\nVIP用户可以免费阅读全部漫画哦~")
coll.delegate = self
coll.dataSource = self
return coll
}()
使用阶段
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let comicList = vipLists?[indexPath.section]
let cell = collectionView.dequeueReusableCell(for: indexPath, cellType: BCComicCCell.self)
cell.style = .withTitle
cell.model = comicList?.comics?[indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionElementKindSectionHeader {
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, for: indexPath, viewType: BCComicSeactionHeader.self)
let comicList = vipLists?[indexPath.section]
headerView.bcModel = comicList
// headerView.delegate = self
return headerView
}else {
let footView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, for: indexPath, viewType: BCComicSeactionFoot.self)
return footView
}
}
在自定义的Cell或者Head或者Foot中
override func configUI() {} 的方法里实现布局即可
Class类的层级分布

FC3CD187-2F83-428C-91A7-C4C262571398.png
记忆点
// 对于SnpKit的扩展 多控件组的约束
let buttonArray = [deviceDirectionButton,lightButton,chapterButton];
buttonArray.snp.distributeViewsAlong(axisType: .horizontal, fixedSpacing: 60, leadSpacing: 40, tailSpacing: 40)
buttonArray.snp.makeConstraints {
$0.top.equalTo(menuSlider.snp.bottom).offset(10)
$0.bottom.equalToSuperview()
}
网友评论