ZPSegmentBar 该框架分为OC和Swfit两个版本:点击前往OC版本
var style = ZPStyle()
style.isScrollEnabled=true; //标题是否可以滚动,默认为true;
style.isShowCover = true //标题是否显示遮盖,默认为true;
style.isShowBottomLine=true //标题下方是否显示BottomLine,默认为true;
style.isNeedScale=true //标题文字是否缩放,默认为true;
.
.
.
let segmentView = ZPSegmentBarView(frame: frame, titles: titles, style: style, childVcs: childVcs, parentVc: self)
view.addSubview(segmentView)
var style = ZPStyle()
style.isScrollEnabled=false; //标题是否可以滚动,默认为true;
style.isShowCover = false //标题是否显示遮盖,默认为true;
style.isShowBottomLine=true //标题下方是否显示BottomLine,默认为true;
style.isNeedScale=true //标题文字是否缩放,默认为true;
.
.
.
let layout = ZPPageBarLayout()
layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
layout.minimumLineSpacing=10 //行距
layout.minimumInteritemSpacing=10 //item之间的间距
layout.columns=8 //列数
layout.rows = 3 //行数
let pageBarView = ZPPageBarView(frame: frame, titles: titles, style: style, layout: layout)
pageBarView.dataSource=self //设置数据源代理,并且实现数据源方法
pageBarView.registerCell(UICollectionViewCell.self, reusableIdentifier: kCollectionViewCellID)
view.addSubview(pageBarView)
extension ViewController : ZPPageBarViewDataSource
{
func numberOfSections(in pageBarView: ZPPageBarView) -> Int {
return 4
}
func pageBarView(_ pageBarView: ZPPageBarView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return 61
} else if section == 1 {
return 18
} else if section == 2 {
return 40
} else {
return 18
}
}
func pageBarView(_ pageBarView: ZPPageBarView, collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCollectionViewCellID, for: indexPath)
cell.backgroundColor = UIColor.randomColor()
return cell
}
}
如果是导航控制器,我们需要在集成的View中 设置 automaticallyAdjustsScrollViewInsets=false
ZPSegmentBar is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ZPSegmentBar', '~> 0.1.5'
gzp, zswangzp@163.com
ZPSegmentBar is available under the MIT license. See the LICENSE file for more info.