RainbowNavigation
是由Swfit2.0编写。它允许你在各种情况下动画改变UINavigationBar
的backgroundColor。
RainbowNavigation
主要能做以下几件事:
- 任意改变
UINavigationBar
的背景色(其中包括透明) - 为
UINavigationBar
添加Material Design风格的状态栏颜色加深 UINavigationBar
的背景色在navigationController进行Push或Pop的过程中,动画改变。- 为
UINavigationController
添加全屏大小的手势识别。
- iOS 8.0+
- Swift 3.0 +
在Podfile中添加下面代码,然后执行pod install
pod 'RainbowNavigation
在Cartfile添加以下代码,然后执行carthage update
。
github "DanisFabric/RainbowNavigation"
通过RainbowNavigation
来设置UINavigationBar
的背景色不会出现色差问题,并且能够直接将navigationBar的背景色设置为透明:
navigationBar.df_setBackgroundColor(UIColor.clearColor())
重置背景色:
navigationBar.ll_reset() // 恢复默认,取消之前的颜色设置的影响
设置StatusBar的背景颜色:
navigationBar.df_setStatusBarMaskColor(UIColor.blackColor().colorWithAlphaComponent(0.1))
- 将
UINavigationController
绑定给RainbowNavigation
:
lazy var rainbowNavigation = LLRainbowNavigation()
override func viewDidLoad() {
super.viewDidLoad()
if let navController = self.navigationController {
rainbowNavigation.wireTo(navigationController: navController)
}
}
UIViewController
实现RainbowColorSource
协议,navigationBar的颜色:
@objc public protocol LLRainbowColorSource {
optional func navigationBarInColor() -> UIColor // ViewController被Push进去的时候,UINavigationBar将转变的背景色
optional func navigationBarOutColor() -> UIColor // ViewController被Pop出去的时候,UINavigationBar将转变的颜色
}
RainbowNavigation
的使用十分简单,可以通过下载demo项目来查看Gif图片显示的功能的实现方式。
DanisFabric, [email protected]
The MIT License (MIT)
Copyright © 2015 DanisFabric
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.