Easy way to dynamically change UINavigationBar , implemented in swift2.2
This project is heavily inspired by LTNavigationBar. SurfingNavigationBar provides you a chance to use pure Swift alternative in your next app.
Firstly drag SurfingNavigationBar.swift
into your project.
The UINavigationBar Extension
includes 4 methods to manage UINavigationBar's appearance
func surfing_setBackgroundColor(backgroundColor:UIColor)
func surfing_setElementsAlpha(alpha:CGFloat)
func surfing_setTranslationY(translationY:CGFloat)
func surfing_reset()
Usually you should implement below function to avoid any side effects:
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.navigationBar.surfing_reset()
}
I have implement the demo app that can help understand SurfingNavigationBar in a very swift and clear way,check out demo app for more details.
SurfingNavigationBar implement self.setBackgroundImage(UIImage(), forBarMetrics: .Default)
which remove the original appearance of UINavigationBar and we add a overlayView:UIView
on UINavigationBar in runtime.The color,alpha,transfromY of overlayView is the variables we're managing.
Xcode 7.3 , Swift 2.2
Peiwei Chen
[email protected]
Blog
Copyright (c) 2016 Peiwei Chen [email protected]. See the LICENSE file for license rights and limitations (MIT).