swift3自定义导航条(一)

//
//  TGPageStyle.swift
//  TGPageView
//
//  Created by targetcloud on 2017/3/22.
//  Copyright © 2017年 targetcloud. All rights reserved.
//

import UIKit

class TGPageStyle {
    var titleViewHeight : CGFloat = 44
    var titleFont : UIFont = UIFont.systemFont(ofSize: 15.0)
    var isScrollEnable : Bool = false
    
    var titleMargin : CGFloat = 20
    
    var normalColor : UIColor = UIColor(r:255,g:255,b:255)
    var selectColor : UIColor = UIColor.random()//UIColor(r:255,g:127,b:0)
    
    var isShowBottomLine : Bool = true
    var bottomLineColor : UIColor = UIColor.random()
    var bottomLineHeight : CGFloat = 2
    var bottomLineExtendWidth : CGFloat = 4
    var bottomLineMargin : CGFloat = 1
    
    var isNeedTitleScale : Bool = false
    var scaleRange : CGFloat = 1.2
    
    var isShowCoverView : Bool = false
    var coverBgColor : UIColor = UIColor.random()
    var coverAlpha : CGFloat = 0.4
    var coverMargin : CGFloat = 8
    var coverRadius : CGFloat = 8
    var coverHeight : CGFloat = 25
    
}

可以通过上面的属性定义各种外观及功能,总体上可以实现 滚动或不滚动(等分)、遮照、放大缩小、颜色渐变、滚动跟踪条等功能,并可以通过上面的功能相互组合和配置实现各种主流APP的所有导航条特性

调用代码如下

//
//  ViewController.swift
//  TGPageView
//
//  Created by targetcloud on 2017/3/22.
//  Copyright © 2017年 targetcloud. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        automaticallyAdjustsScrollViewInsets = false//不要调整SV内边距
        let pageViewFrame = CGRect(x: 0, y: 64, width: view.bounds.width, height: view.bounds.height - 64 )//非scrollView设置64
//        let titles = ["推荐","视频","图片","段子","投票"]
        let titles = ["推荐","视频","这是一个测试","图片","段子","投票","排行","互动区","网红","社会","美女","冷知识","游戏"]
        
        let style = TGPageStyle()
        style.isScrollEnable = true
        style.isShowBottomLine = true
        style.isNeedTitleScale = true
//        style.isShowCoverView = true
        
        var childVCs = [UIViewController]()
        for _ in 0..<titles.count {
            let vc = UIViewController()
            vc.view.backgroundColor = UIColor.random()
            childVCs.append(vc)
        }
    
        let pageView = TGPageView(frame: pageViewFrame, titles: titles, titleStyle: style, childVCs: childVCs, parentVC: self)
        view.addSubview(pageView)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

运行效果如下

1 不可滚动,等分,遮照形式,底下无跟踪滚动条


2 不可滚动,等分,遮照形式,底下有跟踪滚动条


3 可滚动,遮照形式,底下有跟踪滚动条


4 可滚动,遮照形式,底下无跟踪滚动条


5 可滚动,无遮照,底下有跟踪滚动条


6 不可滚动,等分,无遮照,底下有跟踪滚动条


7 文字缩放支行


8颜色渐变支持


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值