项目介绍:
[Swift] 线性视图布局
主要代码:
[Objective-C] 查看源文件 复制代码
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(CollectionView)
}
// MARK: - UICollectionView 懒加载方法
private lazy var CollectionView: UICollectionView = {
let clv = UICollectionView(frame:CGRectMake(0, 100, UIScreen.mainScreen().bounds.size.width, 300), collectionViewLayout:LXLineFlowLayout())
clv.registerClass(LXLineViewCell.self, forCellWithReuseIdentifier: "keyboardCell")
clv.dataSource = self
return clv
}()
var startRefresh: (() -> (NSMutableArray)) {
get {
return {
() -> (NSMutableArray)
in
let arr = NSMutableArray()
for i in 0...4 {
arr.addObject("\(i+1)")
}
return arr
}
}
}
}
extension ViewController : UICollectionViewDataSource{
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
return self.startRefresh().count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("keyboardCell", forIndexPath: indexPath) as! LXLineViewCell
let arr = self.startRefresh()
cell.indexStr = arr[indexPath.item] as? String
return cell
}
}
联系QQ:3141833116

LXLAYOUT.zip
(377.23 KB, 下载次数: 365)
2016-9-5 10:16 上传
点击文件名下载附件
视图布局
