这边是自定义collectionViewLayout方法来实现多段section的布局 当然是简单的布局 如果要实现不规则布局 只要在下面的attributs 那个类里面做一个if判断设置就可以了
这里附上源码 现学现卖 实现了最简单的布局
import UIKit
class ProfileController: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource {
var collectionView:UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
let layout = ProfileCustomLayout()
// let collectionW = UIScreen.mainScreen().bounds.size.width
// let collectionH = UIScreen.mainScreen().bounds.size.height - (self.navigationController?.navigationBar.size.height)! - (self.tabBarController?.tabBar.size.height)!
collectionView = UICollectionView(frame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height),collectionViewLayout: layout )
collectionView.dataSource = self
collectionView.delegate = self
//注册模板
collectionView.registerClass(ProfileCell.self, forCellWithReuseIdentifier: "Cell")
collectionView.backgroundColor = UIColor.whiteColor()
view.addSubview(collectionView)
}
//段数
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 3
}
//行数
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {