自定义banner小工具-高度复用
2021-09-29 本文已影响0人
不拘小节123456
直接看代码简单易用
//创建
lazy var firstBannerView: KCBannerView = {
let bannerView = KCBannerView(registerClass: KCHomeBannerCell.self,timeNum: 5)
self.view.addSubview(bannerView)
bannerView.changeShowStatus(isShow: true)
bannerView.backgroundColor = .gray
bannerView.didSelectBlock = { [weak self, weak bannerView](data) in
print("didSelectBlock")
}
bannerView.scrollDidAndEndBlock = { [weak self, weak bannerView](index) in
print("didSelectBlock")
}
return bannerView
}()
firstBannerView.frame = CGRect(x: 20, y: 20, width: 200, height: 100)
//设置数据
firstBannerView.dataList = [1,2,3,4,5,6]
firstBannerView.cellSize = CGSize(width: 200, height: 100)
//自定义cell
class KCHomeBannerCell: UICollectionViewCell,BannerCellDataProtocol {
func setData(data: Any) {
let temp = data as? Int ?? 0
if temp % 2 == 0 {
self.backgroundColor = .red
} else {
self.backgroundColor = .green
}
print("data = \(data)")
}
}
//附带左右滑动扩展小组件,采用组合模式,详情可以看demo
demo:
https://github.com/riceForChina/bannerView.git