Latest 1.0.4
Homepage https://github.com/weixhe/CVNavigationController
License MIT
Platforms ios 8.0, requires ARC
Authors

简易封装NavController,可设置标准的left,right,title, 也可设置多items,自定义titleView,为items设置space等

引入工程

pod 'CVNavigationController'     // 引入组件 - navBar

使用方法

在AppDelegate中设置nabBar的通用属性
CVNavigationAppearance.share.itemTextColor = UIColor.orange
CVNavigationAppearance.share.itemFont = UIFont.systemFont(ofSize: 15)

CVNavigationAppearance.share.titleColor = UIColor.orange
CVNavigationAppearance.share.titleFont = UIFont.systemFont(ofSize: 20)

在控制器的适当的位置,比如ViewDidLoad() 方法中直接设置相关属性

  1. 显示单个

    cv_navigationItem?.leftItem = CVBarButtonItem(title: "<<", image: nil, target: self, action: #selector(back))
    cv_navigationItem?.rightItem = CVBarButtonItem(title: "share", target: self, action: #selector(share))
  2. 显示多个item

    // 左侧
    let close = CVBarButtonItem(title: "关闭", target: nil, action: nil)
    let back = CVBarButtonItem(title: "返回", target: nil, action: nil)
    cv_navigationItem?.leftItems = [close, back]
    
    // 右侧
    let space1 = CVBarSpaceItem(space: 5)
    let share = CVBarButtonItem(title: "分享", target: self, action: #selector(share))
    let refresh = CVBarButtonItem(title: "刷新", target: nil, action: nil)
    cv_navigationItem?.rightItems = [space1, share, refresh]
  3. 显示title

    self.title = "首页-2"
    //  或   cv_navigationItem?.title = "首页-2"
  4. 设置titleView

    let titleView = UIButton(type: .system)
    titleView.setTitleColor(UIColor.blue, for: .normal)
    titleView.setTitle("点击已分享", for: .normal)
    titleView.addTarget(self, action: #selector(shareToFriend), for: .touchUpInside)
    titleView.frame = CGRect(x: 0, y: 0, width: 80, height: 44)
    cv_navigationItem?.titleView = titleView
  5. 禁止/打开 侧滑
    通过nav的 slidingBackEnable 属性控制是否允许侧滑

    override func viewWillAppear(_ animated: Bool) {
      super.viewWillAppear(animated)
      self.cv_navigationController?.slidingBackEnable = slidingBackEnable
    }
    
    override func viewWillDisappear(_ animated: Bool) {
     super.viewWillDisappear(animated)
     self.cv_navigationController?.slidingBackEnable = true
    }

Latest podspec

{
    "name": "CVNavigationController",
    "version": "1.0.4",
    "summary": "CVNavigationController",
    "swift_version": "4.2",
    "description": "u7b80u6613u5c01u88c5NavControlleruff0cu53efu8bbeu7f6eu6807u51c6u7684leftuff0crightuff0ctitleuff0c u4e5fu53efu8bbeu7f6eu591aitemsuff0cu81eau5b9au4e49titleViewuff0cu4e3aitemsu8bbeu7f6espaceu7b49",
    "homepage": "https://github.com/weixhe/CVNavigationController",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "weixhe": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/weixhe/CVNavigationController.git",
        "tag": "1.0.4"
    },
    "source_files": "CVNavigationController/Classes/*.{swift}",
    "resources": "CVNavigationController/Classes/*.bundle",
    "requires_arc": true
}

Pin It on Pinterest

Share This