CVNavigationController
简化封装 navCtrl,可设置标准的 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() 方法中直接设置相关属性
- 显示单个
cv_navigationItem?.leftItem = CVBarButtonItem(title: "<<", image: nil, target: self, action: #selector(back))
cv_navigationItem?.rightItem = CVBarButtonItem(title: "share", target: self, action: #selector(share))
- 显示多个 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]
- 显示 title
self.title = "首页-2"
// 或 cv_navigationItem?.title = "首页-2"
- 设置 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