YZTNavigationBar
定制 UINavigationBar 样式,可以全局统一设置默认样式,在各个页面灵活定制自己的样式。
设置说明
要使用 CocoaPods 将 YZTNavigationBar 集成到您的 Xcode 项目中,请在 Podfile 中指定它
pod 'YZTNavigationBar',并在您的代码中添加 import YZTNavigationBar。
手动
只需将 YZTNavigationBar 文件夹添加到您的项目中。
基本示例
- 1、普通样式
func setNavbarAppearance() {
// 导航栏颜色
navBarBarTintColor = .white
// 导航栏透明度
navBarBackgroundAlpha = 1
// 导航栏两边按钮颜色
navBarTintColor = .black
// 导航栏上标题颜色
navBarTitleColor = .black
// 导航栏底部分割线是否隐藏
navBarShadowImageHidden = true;
// 状态栏是 default 还是 lightContent
statusBarStyle = .default
}
- 2、自定义样式
func setNavbarAppearanc() {
// 设置导航栏颜色
navBar.barBackgroundColor = UIColor(red: 247/255.0, green: 247/255.0, blue: 247/255.0, alpha: 1.0)
// 设置初始导航栏透明度
navBar.yzt_setBackgroundAlpha(alpha: 0)
// 设置标题文字颜色
navBar.titleLabelColor = UIColor.white
navBar.yzt_setRightButton(title: "设置", titleColor: .white)
statusBarStyle = .lightContent
navBar.onClickRightButton = {
}
}
// MARK: - ScrollViewDidScroll
extension YZTPersonalCenterViewController
{
func scrollViewDidScroll(_ scrollView: UIScrollView)
{
let offsetY = scrollView.contentOffset.y
if (offsetY > NAVBAR_COLORCHANGE_POINT)
{
let alpha = (offsetY - NAVBAR_COLORCHANGE_POINT) / CGFloat(kNavBarBottom)
navBar.yzt_setBackgroundAlpha(alpha: alpha)
navBar.yzt_setTintColor(color: UIColor.black.withAlphaComponent(alpha))
navBar.titleLabelColor = UIColor.black.withAlphaComponent(alpha)
statusBarStyle = .default
}
else
{
navBar.yzt_setBackgroundAlpha(alpha: 0)
navBar.yzt_setTintColor(color: .white)
navBar.titleLabelColor = .white
statusBarStyle = .lightContent
}
}
}
如果您有问题,可以查看示例。
兼容性
- 版本 1.0.1 需要 Swift 4.2 和 Xcode 10。