一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我。
Swift 项目底层框架(万能)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5742dee34870791d864adfc8e8b1c765.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d729421302ad0226fb2133ba31add8e5.gif)
import UIKit
class ViewController: UIViewController {
var waterFlowLayoutView = WaterflowView()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
waterFlowLayoutView = WaterflowView(frame: view.bounds)
waterFlowLayoutView.dataSource = self
waterFlowLayoutView.wfDelegate = self
waterFlowLayoutView.autoresizingMask = .flexibleWidth
view.addSubview(waterFlowLayoutView)
}
}
extension ViewController: WaterflowDelegate, WaterflowDataSource {
func numberOfCellsInWaterflow(waterflow: WaterflowView) -> Int {
return 100
}
func waterflow(waterflow: WaterflowView, cellAtIndex index: Int) -> WaterflowViewCell {
var cell = waterflow.dequeueReusableCellWithIdentifier(identifier: "wfCell") as? WaterflowViewCell
if cell == nil {
cell = WaterflowViewCell()
cell?.identifier = "wfCell"
}
cell?.backgroundColor = randomColor()
return cell!
}
func numberOfColumnsInWaterflow(waterflow: WaterflowView) -> Int {
if preferredInterfaceOrientationForPresentation.isPortrait {
return 3
} else {
return 5
}
}
func waterflow(waterflow: WaterflowView, didSelectAtIndex index: Int) {
print(index)
}
func waterflow(waterflow: WaterflowView, heightAtIndex index: Int) -> CGFloat {
return (index % 2 == 0) ? 100 : 50
}
func waterflow(waterflow: WaterflowView, marginForType type: WaterflowMarginType) -> CGFloat {
return 10
}
override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
waterFlowLayoutView.reloadData()
}
func randomColor() -> UIColor {
let red: CGFloat = CGFloat(arc4random_uniform(256))/255
let green: CGFloat = CGFloat(arc4random_uniform(256))/255
let blue: CGFloat = CGFloat(arc4random_uniform(256))/255
let alpha: CGFloat = 1.0
return UIColor.init(red: red, green: green, blue: blue, alpha: alpha)
}
}