ZPSegmentBar 0.1.6

ZPSegmentBar 0.1.6

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017 年 10 月
SwiftSwift 版本3.0
SPM支持 SPM

zswangzP105318 维护。



  • 作者
  • gzp

ZPSegmentBar 框架分为 OC 和 Swift 两个版本:点击前往 OC 版本

##该框架的主要功能包括两部分

1. 模仿今日头条或者是网易新闻 NavigationBar 效果,效果如下图所示

scroll.gif
scroll2.gif

####集成该框架的主要步骤

1. 导入头文件 import ZPSegmentBar
2. 实例化ZPStyle,并且传入我们需要的样式,例如
var style = ZPStyle()
style.isScrollEnabled=true; //标题是否可以滚动,默认为true;
style.isShowCover = true    //标题是否显示遮盖,默认为true;
style.isShowBottomLine=true //标题下方是否显示BottomLine,默认为true;
style.isNeedScale=true      //标题文字是否缩放,默认为true;
.
.
.
3. 实例化 ZPSegmentBarView,并且传入所需要的参数
let segmentView = ZPSegmentBarView(frame: frame, titles: titles, style: style, childVcs: childVcs, parentVc: self)
4. 将创建好的 ZPSegmentBarView 添加到当前View中即可
view.addSubview(segmentView)

2. 封装了一个表情键盘或者是礼物键盘,效果如下图所示

2.gif

####集成该功能的主要步骤

1. 和上面的步骤一样,导入头文件 import ZPSegmentBar
2. 和上面的步骤一样,实例化ZPStyle,并且传入我们需要的样式,例如
var style = ZPStyle()
style.isScrollEnabled=false; //标题是否可以滚动,默认为true;
style.isShowCover = false    //标题是否显示遮盖,默认为true;
style.isShowBottomLine=true //标题下方是否显示BottomLine,默认为true;
style.isNeedScale=true      //标题文字是否缩放,默认为true;
.
.
.
3. 实例化ZPPageBarLayout布局,并且传入我们需要的样式,例如
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                      //行数
4. 实例化ZPPageBarView,并且传入我们需要的参数,设置数据源代理,注册cell
let pageBarView = ZPPageBarView(frame: frame, titles: titles, style: style, layout: layout)

pageBarView.dataSource=self     //设置数据源代理,并且实现数据源方法

pageBarView.registerCell(UICollectionViewCell.self, reusableIdentifier: kCollectionViewCellID)
view.addSubview(pageBarView)

5.实现数据源方法
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 通过 CocoaPods 提供。要安装
它,简单地添加以下行到您的 Podfile 中

pod 'ZPSegmentBar', '~> 0.1.5'

作者

简书连接

gzp, [email protected]

许可证

ZPSegmentBar 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。