An easy way to change backgroundColor of UINavigationBar when Push & Pop

Overview

image1

RainbowNavigation 中文介绍

Feature

RainbowNavigation is written in Swift 2.0. It helps you change the backgroundColor of UINavigationBar in animations and transitions.

image1 image2 image3

Requirements

  • iOS 8.0 +
  • Swift 3.0 +

Install

Carthage

Add following code to your Cartfile, and run carthage update:

github "DanisFabric/RainbowNavigation"

Usage

Change backgroundColor of UINavigationBar

Make UINavigationBar transparent

navigationBar.df_setBackgroundColor(UIColor.clearColor())

Restore the default values

navigationBar.df_reset()

You can add a mask for statusBar:

navigationBar.df_setStatusBarMaskColor(UIColor.blackColor().colorWithAlphaComponent(0.1))

Support UINavigationController Operations

  1. wire the UINavigationController to RainbowNavigation
lazy var rainbowNavigation = RainbowNavigation()
   override func viewDidLoad() {
        super.viewDidLoad()
        if let navController = self.navigationController {
            rainbowNavigation.wireTo(navigationController: navController)
        }
    }
  1. Your viewController need to confirm RainbowColorSource protocol, and offer the color which navigationBar will change into.
@objc public protocol RainbowColorSource {
    optional func navigationBarInColor() -> UIColor    
    optional func navigationBarOutColor() -> UIColor   
}

Demo

RainbowNavigation is simple to use, downlaod the demo project and learn more.

Author

DanisFabric, [email protected]

License

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.
You might also like...
A UINavigationController subclass that support pop interactive UINavigationbar with hidden or show.
A UINavigationController subclass that support pop interactive UINavigationbar with hidden or show.

KDInteractiveNavigationController Features ✨ UINavigationController interactive with UINavigationBar hidden or show Hide all UINavigationController ba

A UINavigationController subclass that support pop interactive UINavigationbar with hidden or show.
A UINavigationController subclass that support pop interactive UINavigationbar with hidden or show.

KDInteractiveNavigationController Features ✨ UINavigationController interactive with UINavigationBar hidden or show Hide all UINavigationController ba

SwiftUI library to display a clock. You can move the arms to change the time, change the style of the clock and customise some configurations.
SwiftUI library to display a clock. You can move the arms to change the time, change the style of the clock and customise some configurations.

SwiftClockUI Clock UI for SwiftUI This library has been tested ✅ 💻 macOS Catalina 10.15.3 ✅ 💻 macOS Big Sur 11.6 ✅ 📱 iOS 13 ✅ 📱 iOS 14 ✅ 📱 iOS 15

ElongationPreview is an elegant UI push-pop style view controller
ElongationPreview is an elegant UI push-pop style view controller

ElongationPreview is an elegant UI push-pop style view controller

Completion Block for UINavigationController Push/Pop UIViewController

JNAPushPopCompletionBlock Synopsis Completion block for [self.navigationController pushViewController:(nonnull UIViewController *) animated:(BOOL)] an

OS X app for sending push with Apple Push Notification service (APNs)
OS X app for sending push with Apple Push Notification service (APNs)

pushHandle OS X app for sending push with Apple Push Notification service (APNs) About This app was created just to allow painless testing of push not

'Minimalistic Push' is a minimalistic push-up application now built with Flutter.
'Minimalistic Push' is a minimalistic push-up application now built with Flutter.

Minimalistic Push Minimalistic Push is one of the simplest push-up trackers out there. You can track your push-ups in the training mode and see an ove

Push Hero - pure Swift native macOS application to test push notifications
Push Hero - pure Swift native macOS application to test push notifications

Dropdowns ❤️ Support my app ❤️ Push Hero - pure Swift native macOS application to test push notifications Quick Access - Organise files in the Mac men

Scrollable UINavigationBar that follows the scrolling of a UIScrollView
Scrollable UINavigationBar that follows the scrolling of a UIScrollView

A custom UINavigationController that enables the scrolling of the navigation bar alongside the scrolling of an observed content view Versioning notes

Zingle – An alert will display underneath your UINavigationBar 🎅
Zingle – An alert will display underneath your UINavigationBar 🎅

Zingle Zingle – An alert will display underneath your UINavigationBar 🎅 💥 Note: Zingle has a dependency to have a UINavigationController in your app

A UINavigationBar extension to show loading effects
A UINavigationBar extension to show loading effects

BusyNavigationBar A UINavigationBar extension to show loading effects above navigation bar's background. Screenshot Stripes Bars Your custom layer Usa

Scrollable UINavigationBar that follows the scrolling of a UIScrollView
Scrollable UINavigationBar that follows the scrolling of a UIScrollView

A custom UINavigationController that enables the scrolling of the navigation bar alongside the scrolling of an observed content view Versioning notes

iOS UI library to show and hide an extension to your UINavigationBar
iOS UI library to show and hide an extension to your UINavigationBar

ADNavigationBarExtension is a UI library written in Swift. It allows you to show and hide an extension to your UINavigationBar Features Use Extensible

SwiftySideMenu is a lightweight and easy to use side menu controller to add left menu and center view controllers with scale animation based on Pop framework.
SwiftySideMenu is a lightweight and easy to use side menu controller to add left menu and center view controllers with scale animation based on Pop framework.

SwiftySideMenu SwiftySideMenu is a lightweight, fully customizable, and easy to use controller to add left menu and center view controllers with scale

Easy-to-use segues in SwiftUI, allowing for presenting views using common UIKIt Segue types - push, modal and popover
Easy-to-use segues in SwiftUI, allowing for presenting views using common UIKIt Segue types - push, modal and popover

Easy-to-use segues in SwiftUI, allowing for presenting views using common UIKIt Segue types - push, modal and popover

Localization of the application with ability to change language
Localization of the application with ability to change language "on the fly" and support for plural form in any language.

L10n-swift is a simple framework that improves localization in swift app, providing cleaner syntax and in-app language switching. Overview 🌟 Features

Mac app to change .ipa file app icons and display names

IPAEdit Mac app to change .ipa file app icon, display name, and app version to avoid updates Compatible with macOS 10.11+ Install To install either cl

A menu bar app to change input source swiftly using shortcuts on macOS Big Sur or later.

Source Switcher A menu bar app to change input sources swiftly using shortcuts on macOS Big Sur and later. View screenshots Introduction This app uses

Change SwiftUI Navigation Bar Color for different View
Change SwiftUI Navigation Bar Color for different View

SwiftUINavigationBarColor Change SwiftUI NavigationBar background color per screen. Usage For NavigationBarColor to work, you have to set the Navigati

Comments
  • 混编,RainbowNavigation.swift 中的代理方法无法触发

    混编,RainbowNavigation.swift 中的代理方法无法触发

    现在通过打断点发现RainbowNavigation.swift中的UINavigationControllerDelegate相关的代理方法的没有触发过,自然数据源方法也不会触发。

    我自己也写了个 Swift 文件在项目中测试,同样无法触发 UINavigationController 对应的代理方法(e.g. navigationViewController willShowViewController)。

    求救...我觉得应该是我混编姿势有问题...

    opened by siegrainwong 2
  • [CHANGE] use of UIScreenEdgePanGestureRecognizer instead of UIPanGestureRecognizer for drag pop gesture

    [CHANGE] use of UIScreenEdgePanGestureRecognizer instead of UIPanGestureRecognizer for drag pop gesture

    This change limits the position of the drag to pop gesture to the left edge of the screen, similar to the native back swipe gesture. Also other pan gestures can be added to the view without being cancelled by the RainbowDragPop gesture.

    opened by anneWe 0
  • Background View overlaps Left/RightNavigationItems

    Background View overlaps Left/RightNavigationItems

    Hello!

    I'm having an issue when I'm coming back (pop) to a UIViewController that has left and/or right navigationItems. When I wire the RainbowNavigation to the UIViewController navigationController, set the "navigationBarInColor()", and pop back to that viewController (dragging or not), the colored background view overlaps the navigationItems (except the title or titleView).

    override func viewDidLoad() {
            super.viewDidLoad()
    
            let button = UIBarButtonItem(title: "HELLO", style: .plain, target: nil, action: nil)
            self.navigationItem.setRightBarButton(button, animated: true)
    
            if let navigationController = navigationController {
                rainbowNavigation.wireTo(navigationController: navigationController)
            }
    }
    
    ...
    
    func navigationBarInColor() -> UIColor {
            return navColor
    }
    

    I have tested it in my own app as in the ExamleApp, and it happens on both. I have been able to debug it, and found that the navigatinoBar.subviews order is the problem, when poping back the ViewController, the layers are rearranged and the backgroundView place itself over the NavigationItems and behind the (TitleView or Title).

    I was not able to fix it yet, has anyone encountered this problem too???

    opened by EstebanVallejo 1
  • Limit PanGesture

    Limit PanGesture

    Hi, It would be nice to have a variable to restrict the zone of the PanGesture, because the user could close accidentally the Controller. I patch the code in RainbowDragPop.swift to restrict the PanGesture for the first 30px:

    func handlePan(_ panGesture:UIPanGestureRecognizer) {
            let offset = panGesture.translation(in: panGesture.view)
            let velocity = panGesture.velocity(in: panGesture.view)
            let position = panGesture.location(in: panGesture.view) //EDIT
    
            switch panGesture.state {
            case .began:
                if(position.x > 30){ return; } //EDIT
    
                if !self.popAnimator.animating {
    

    Regards

    opened by suikadev 1
Owner
danisfabric
danisfabric
A UINavigationController subclass that support pop interactive UINavigationbar with hidden or show.

KDInteractiveNavigationController Features ✨ UINavigationController interactive with UINavigationBar hidden or show Hide all UINavigationController ba

Kingiol 154 Dec 3, 2022
A UINavigationBar extension to show loading effects

BusyNavigationBar A UINavigationBar extension to show loading effects above navigation bar's background. Screenshot Stripes Bars Your custom layer Usa

Günay Mert Karadoğan 992 Dec 3, 2022
Scrollable UINavigationBar that follows the scrolling of a UIScrollView

A custom UINavigationController that enables the scrolling of the navigation bar alongside the scrolling of an observed content view Versioning notes

Andrea Mazzini 6.1k Jan 6, 2023
iOS UI library to show and hide an extension to your UINavigationBar

ADNavigationBarExtension is a UI library written in Swift. It allows you to show and hide an extension to your UINavigationBar Features Use Extensible

FABERNOVEL 58 Aug 29, 2022
Change SwiftUI Navigation Bar Color for different View

SwiftUINavigationBarColor Change SwiftUI NavigationBar background color per screen. Usage For NavigationBarColor to work, you have to set the Navigati

Hai Feng Kao 18 Jul 15, 2022
Simple and integrated way to customize navigation bar experience on iOS app.

NavKit Simple and integrated way to customize navigation bar experience on iOS app. It should save our time that we usually use to make abstraction of

Wilbert Liu 37 Dec 7, 2022
Make SwiftUI Navigation be easy

VNavigator VNavigator is a clean and easy-to-use navigation in SwiftUI base on UINavigationController in UIKit Installation From CocoaPods CocoaPods i

Vu Vuong 10 Dec 6, 2022
SwiftUINavigator: a lightweight, flexible, and super easy library which makes SwiftUI navigation a trivial task

The logo is contributed with ❤️ by Mahmoud Hussein SwiftUINavigator is a lightwe

OpenBytes 22 Dec 21, 2022
Simple UIButton subclass with additional state change animations (e.g. backgroundColor) and missing features

SimpleButton UIButton subclass with animated, state-aware attributes. Easy to subclass and configure! Full API docs Usage Just create your own SimpleB

Andreas Tinoco Lobo 169 Sep 14, 2022
UINavigationBar Category which allows you to change its appearance dynamically

Deprecated This lib uses a hacky way to achieve the result, in the new iOS version, the structure of UINavigation is changed and this lib no longer wo

Leo 4.5k Dec 3, 2022