AFSubtitleNavigationItem
示例
要运行示例项目,请首先克隆仓库,然后在 Example 目录中运行 pod install
。
需求
需要 iOS 9.0 或更高版本。
安装
AFSubtitleNavigationItem 可以通过 CocoaPods 获得。要安装它,请将以下行添加到您的 Podfile 中
pod 'AFSubtitleNavigationItem'
使用方法
首先在您的 AppDelegate
中导入 AFSubtitleNavigationItem
import AFSubtitleNavigationItem
在controller的 viewDidLoad
方法中写入以下内容
navigationItem.isSubtitleEnabled = true
navigationItem.titleLabel?.text = "Title"
navigationItem.subtitleLabel?.text = "Subtitle"
请确保这个视图控制器实际上有一个导航控制器,即它不是在导航控制器堆栈之外直接展示。您还可以将自定义导航项添加到要展示的视图控制器,并直接使用AFSubtitleNavigationItem
属性。
应用全貌
您可以使用以下代码轻松自定义整个应用程序中的所有导航项
自定义标题
UINavigationItem.appearance.titleTextColor = .darkGray
UINavigationItem.appearance.titleTextFont = UIFont.systemFont(ofSize: 17, weight: .medium)
UINavigationItem.appearance.titleTextShadowColor = UIColor.black.withAlphaComponent(0.05)
UINavigationItem.appearance.titleTextShadowOffset = CGSize(width: 0.5, height: 0.5)
自定义副标题
UINavigationItem.appearance.subtitleTextColor = .darkGray
UINavigationItem.appearance.subtitleTextFont = UIFont.systemFont(ofSize: 13, weight: .thin)
UINavigationItem.appearance.subtitleTextShadowColor = UIColor.black.withAlphaComponent(0.05)
UINavigationItem.appearance.subtitleTextShadowOffset = CGSize(width: 1, height: 1)
作者
Ahmed Fathi, [email protected]
许可证
AFSubtitleNavigationItem 在MIT许可证下可用。有关更多信息,请见LICENSE文件。