UINavigationBar Category which allows you to change its appearance dynamically

Overview

LTNavigationbar

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 works anymore, so please check these alternatives:

swift version

https://github.com/ltebean/LTNavigationBar/tree/swift3.0

Purpose

It is hard to change the appearance of UINavigationBar dynamically, so I made this lib to make the job easy.

Demo

1. Changing the background color:

LTNavigationbar

2. Making navigation bar scroll along with a scroll view:

LTNavigationbar

Usage

First, import this lib:

#import "UINavigationBar+Awesome.h"

The category includes lots of method that helps to change UINavigationBar's appearance dynamically:

@interface UINavigationBar (Awesome)
- (void)lt_setBackgroundColor:(UIColor *)backgroundColor;
- (void)lt_setElementsAlpha:(CGFloat)alpha;
- (void)lt_setTranslationY:(CGFloat)translationY;
- (void)lt_reset;
@end

You can call the various setter wherever you want, like:

[self.navigationController.navigationBar lt_setBackgroundColor:[UIColor blueColor]];

And usually in viewWillDisappear, you should call this method to avoid any side effects:

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar lt_reset];
}

See the example for details~

Comments
  • TopView is to small

    TopView is to small

    I tried to create your example in code instead of in the storyboard.

    In AppDelegate I created:

    let vc = Page1ViewController()
    window?.rootViewController = UINavigationController(rootViewController: vc)
    

    Page1ViewController is:

    @objc(Page1ViewController)
    class Page1ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
      let cellIndentifier = "cell"
      let NAVBAR_CHANGE_POINT:CGFloat = 50
    
      @IBOutlet weak var tableView: UITableView!
      var topView:UIView!
      var topImageView: UIImageView?
    
    
      override func viewDidLoad() {
        super.viewDidLoad()
    
        self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "someAction"), animated: true)
    
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellIndentifier)
        self.navigationController?.navigationBar.lt_setBackgroundColor(UIColor.clearColor())
    
    
        topView = UIView(frame: CGRectMake(0, 0, 320, 212))
        topView.backgroundColor = UIColor.yellowColor()
        tableView.addSubview(topView)
    
    
        let img = UIImage(named: "bg2")
        topImageView = UIImageView(image: img)
        topImageView?.frame = CGRectMake(0, -89, 320, 307)
        topImageView?.contentMode = UIViewContentMode.ScaleToFill
        topView.addSubview(topImageView!)
    
        topView.superview?.sendSubviewToBack(topView)
    
      }
      ...
    }
    

    In the nib of Page1ViewController I just inserted a UITableView and linked the outlet to tableView.

    Here is the result when I run the app:

    ios_simulator_-iphone_5-iphone_5___ios_7_1__11d167

    It works like your demo app with the exception that the header does not have the correct height. How can I change that?

    Thanks for help!

    opened by steffimueller 16
  • Problem with back button not working

    Problem with back button not working

    Awesome code for a nice effect, thank you. I have one problem where the back button does not work any longer when I navigate down a few layers. Any idea what that could be? It might be my code.

    opened by reggatta 6
  • reset  无效

    reset 无效

    • (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController.navigationBar lt_reset]; }

    push to other Controller navigationBar color can not set to default

    opened by bluesky0109 5
  • iOS 10 Navigation bar is not set to transparent

    iOS 10 Navigation bar is not set to transparent

    I am writing code for app with future support so basically i'm looking at all side previous versions, current version, as well as future version which will be iOS 10.

    This category works perfect until iOS 9.3.3 but in iOS 10 its not working, i've tested on both iDevice and Simulator

    I'm setting clear colour for navigation bar at viewDidLoad as below

    [self.navigationController.navigationBar setShadowImage:[UIImage new]]; [self.navigationController.navigationBar lt_setBackgroundColor:[UIColor clearColor]];

    Please someone help me out with this.

    I'm sorry for my english, i don't know what language you're using 😜

    Thanks.

    opened by Pratik948 3
  • 您好,使用了您的框架结果被拒

    您好,使用了您的框架结果被拒

    不知道苹果抽什么风,Your app uses or references the following non-public APIs:

    UIInputSetHostView, UIKeyboard, UINavigationItemView, UIPeripheralHostView

    The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change.

    opened by zhuyu99 2
  • iOS 11 崩溃

    iOS 11 崩溃

    LTNavigationBar[11369:4642197] [Accessibility] ****************** Loading GAX Client Bundle **************** 2017-06-28 14:30:40.795882+0800 LTNavigationBar[11369:4642197] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UINavigationBar 0x1039250a0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key _leftViews.' *** First throw call stack: (0x186ed9858 0x1856b0528 0x186ed9520 0x187a26e88 0x18796ceac 0x10367efc0 0x10367e05c 0x10367de80 0x18d9e000c 0x19d4e7f00 0x18d705b5c 0x18d7ab6c0 0x18d871a0c 0x18dd49978 0x18dd4df1c 0x18d862b9c 0x18d7181f4 0x18dd38364 0x18dd37f24 0x18dd37080 0x18d7164f4 0x18d6e7b38 0x19d4af210 0x18dfe9514 0x18dfeb984 0x18dfe4af0 0x186e80528 0x186e7fe0c 0x186e7d904 0x186d9c280 0x1888adf94 0x18d74b0f0 0x10367ea80 0x185b8de40) libc++abi.dylib: terminating with uncaught exception of type NSException

    opened by boai 2
  • Crashed on iOS11

    Crashed on iOS11

    I used a single UINavigationBar(NOT UINavigationController), App crashed on lt_setBackgroundColor method. It seems that UINavigationBar subviews structure has changed.

    opened by wujianbotju 2
  • 不能实现渐变色啊。

    不能实现渐变色啊。

    我有一个方法会频繁调用

    - (void)handlePopGesture:(UIPanGestureRecognizer *)popGesture
    {
        // 计算用户手指划了多远
        CGFloat progress = [popGesture translationInView:self.view].x / (self.view.bounds.size.width * 1.0);
        progress = MIN(1.0, MAX(0.0, progress));
        YPLog(@"%f",progress);
    
        CGFloat r = _endR - _startR;
        CGFloat g = _endG - _startG;
        CGFloat b = _endB - _startB;
    
        UIColor *endColor = [UIColor colorWithRed:_startR + r * progress green:_startG + g * progress blue:_startB + b * progress alpha:1.0f];
    
        [self.navigationController.navigationBar lt_setBackgroundColor:endColor];
    }
    

    随着进度改变Bar的背景颜色。。 发现不好用 颜色不会变

    opened by MichaelHuyp 2
  • 有个问题

    有个问题

    当我在 AppDelegate.m 中调用了如下代码:

    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navBg"]
                                      forBarPosition:UIBarPositionTopAttached
                                          barMetrics:UIBarMetricsDefault];
    

    LCNavigationBar 就会失效,如下图: simulator

    opened by iTofu 2
  • Change width in frame for overlay view

    Change width in frame for overlay view

    There's a problem in iOS7 when opening view controller in landscape. Overlay gets width from screen's width which is 320px for iPhone 4 and not 480px which is expected. Setting width to self.bounds' width resolves this issue.

    opened by michal-czw 2
  • Add support for animated background color change

    Add support for animated background color change

    When using the lt_setBackgroundColorthe color changes somewhat abruptly.

    Ir would be awesome if the color could change in a smoother way with an animation.

    opened by beloso 2
  • Add support to iOS 11 and 12.

    Add support to iOS 11 and 12.

    Hey, Itebean, LTNavigationBar is really a simple and great library, don't let it down. I spent some time to make it work on iOS 11 and 12. Also I have tested it on iOS 8, 9, 10, 11 and 12. Please merge.

    opened by wujianbotju 0
  • 通过这样判断适配iPhonex导航栏高度显示问题

    通过这样判断适配iPhonex导航栏高度显示问题

    - (void)lt_setBackgroundColor:(UIColor *)backgroundColor
    {
        
        
        if (!self.overlay) {
            [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
            //适配iPhoneX
            CGFloat navigationBarHeight = 0;
            if ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO) {
                navigationBarHeight = 44.0f+self.frame.size.height;
            }else{
                navigationBarHeight = 20.f+self.frame.size.height;
            }
            self.overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds),navigationBarHeight)];
            self.overlay.userInteractionEnabled = NO;
            self.overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth;   
            [[self.subviews firstObject] insertSubview:self.overlay atIndex:0];
        }
        self.overlay.backgroundColor = backgroundColor;
    }
    
    opened by kb100824 1
  • 由于iOS11导航栏图层改变产生的问题

    由于iOS11导航栏图层改变产生的问题

    工程适配iOS 11 调用了lt_setBackgroundColor这个方法 导航栏透明时title和rightBarButtonItem显示正常 滑动页面 导航栏出现时title和rightBarButtonItem被遮挡 因为[self insertSubview:self.overlay atIndex:0];这句代码 使self.overlay出现在NavigationBar的最上层

    opened by Wangyixuan 3
Owner
Leo
I am now working as a consultant helping startups to build product. If you need any help, feel free to contact me. 🙂
Leo
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
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
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
FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator

FlowStacks allow you to manage complex SwiftUI navigation and presentation flows with a single piece of state. This makes it easy to hoist that state into a high-level coordinator view. Using this pattern, you can write isolated views that have zero knowledge of their context within the navigation flow of an app.

John Patrick Morgan 471 Jan 3, 2023
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
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

Zhouqi Mo 3.3k Dec 21, 2022
Globally change the appearance of the application. Light/Dark mode and color.

About I tried to create a project where you can globally change the appearance of the application. Perhaps someone was looking for such a solution. ⭐️

Aleksandr Buiakov 5 Aug 30, 2022
An easy way to change backgroundColor of UINavigationBar when Push & Pop

RainbowNavigation 中文介绍 Feature RainbowNavigation is written in Swift 2.0. It helps you change the backgroundColor of UINavigationBar in animations and

danisfabric 789 Dec 3, 2022
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

Renaud Jenny 239 Dec 29, 2022
UIImageView subclass that allows you to display a looped video and dynamically switch it.

AKVideoImageView Motivation AKVideoImageView was created because I wasn't satisfied with the standard AVPlayer when I was implementing a video backgro

Oleksandr Kirichenko 125 Apr 5, 2022
A tiny category on UIView that allows you to set one property: "parallaxIntensity" to achieve a parallax effect with UIMotionEffect

NGAParallaxMotion A tiny category on UIView that allows you to set one property: parallaxIntensity to achieve a parallax effect with UIMotionEffect. S

Michael Bishop 650 Sep 26, 2022
VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.

Features Variable PIN length Underline, border and custom styles The error status with / without shake animation Resetting the error status manually,

Vladimir Kokhanevich 95 Nov 24, 2022
A video decoder built on ffmpeg which allows libpag to use ffmpeg as its software decoder for h264 decoding.

ffavc ffavc is a video decoder built on ffmpeg which allows libpag to use ffmpeg as its software decoder for h264 decoding. Build ffmpeg First, make s

Portable Animated Graphics 8 Nov 24, 2022
UIView subclass that bends its edges when its position changes.

AHKBendableView BendableView is a UIView subclass that bends its edges when its position change is animated. Internally, BendableView contains CAShape

Arek Holko 591 Jul 24, 2022
A UISwitch that infects its superview with its tint color.

UISwitch subclass that 'infects' the parent view with the onTintColor when the switch is turned on. Inspired by this Dribble by Ramotion. Screenshot I

Andrea Mazzini 337 Sep 12, 2022
An Integer type that clamps its value to its minimum and maximum instead of over- or underflowing.

ClampedInteger An Integer type that clamps its value to its minimum and maximum instead of over- or underflowing. Examples let big = ClampedIntege

Berik Visschers 0 Jan 17, 2022
UIView category which makes it easy to create layout constraints in code

FLKAutoLayout FLKAutoLayout is a collection of categories on UIView which makes it easy to setup layout constraints in code. FLKAutoLayout creates sim

Florian Kugler 1.5k Nov 24, 2022
This is a basic mobile app that allows the user to tap a button to change the color of a label.

MYAPP App Description `This is a basic mobile app that allows the user to tap a button to change the color of a label. App Walk-though Required User S

null 0 Nov 27, 2021