FSView
轻松实现悬浮 Section 的效果。要做列表请使用 FSListView,照片墙类型则使用 FSItemView。
安装
pod 'FSView'
如何使用 FSListView
注册 FSListViewCell
let nib = UINib(nibName: "\(yourCustomCell.self)", bundle: nil)
listView.register(nib, forCellWithReuseIdentifier: "\(yourCustomCell.self)")
设置 headerHeight
及 sectionHeight
listView.headerHeight = 400
listView.sectionHeight = 40
遵循 FSListViewDelegate
及 FSListViewDataSource
func viewForHeaderView(_ listView: FSListView) -> UIView {
return yourCustomView
}
func viewForPinSectionHeader(_ listView: FSListView) -> UIView {
return yourCustomView
}
func listView(_ listView: FSListView, numberOfRowsInSection section: Int) -> Int {
return yourDataCount
}
func listView(_ listView: FSListView, cellForRowAt indexPath: IndexPath) -> FSListViewCell {
let cell = listView.dequeueReusableCell(cell: yourCustomCell.self, for: indexPath)
return yourCustomCell
}
func listView(_ listView: FSListView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return listView.automaticDimension
}
如何使用 FSItemView
注册 FSItemViewCell
let nib = UINib(nibName: "\(yourCustomCell.self)", bundle: nil)
itemView.register(nib, forCellWithReuseIdentifier: "\(yourCustomCell.self)")
设置 headerHeight
及 sectionHeight
itemView.headerHeight = 400
itemView.sectionHeight = 40
遵循 FSItemViewDelegate
及 FSItemViewDataSource
func viewForHeaderView(_ itemView:FSItemView) -> UIView {
return yourCustomView
}
func viewForPinSectionHeader(_ itemView:FSItemView) -> UIView {
return yourCustomView
}
func itemView(_ itemView: FSItemView, numberOfItemsInSection section: Int) -> Int {
return yourDataCount
}
func itemView(_ itemView: FSItemView, cellForItemAt indexPath: IndexPath) -> FSItemViewCell {
let cell = itemView.dequeueReusableCell(cell: yourCustomCell.self, for: indexPath)
return yourCustomCell
}
func itemView(_ itemView: FSItemView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> FSEdgeInsets {
return FSEdgeInsets(left: 10, bottom: 0, right: 10)
}
func itemView(_ itemView: FSItemView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = itemView.frame.width / 3 - 15
return CGSize(width: width, height: width)
}