Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:11:20+00:00 2026-06-12T11:11:20+00:00

I am adding gradient to navigation Bar’ layer and it is working fine. Issue

  • 0

I am adding gradient to navigation Bar’ layer and it is working fine.
Issue arrive when I push another view Controller and pop view Controller. Parent view Controller has right Bar Button Item whose color dims when I pop View Controller.
My code is

CGRect navFrame = self.navigationController.navigationBar.frame;
navFrame.origin.y = 0.0f;
[self.navigationController.navigationBar.layer insertSublayer:[AddGradient addGradientToNavigationBar:navFrame] atIndex:0];

code for addGradientToNavigationBar is

+ (CAGradientLayer*)addGradientToNavigationBar:(CGRect)navRect {

    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = navRect;
    gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0] CGColor],
                   (id)[[XAppDelegate getColor] CGColor], nil];

    return gradient;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:11:22+00:00Added an answer on June 12, 2026 at 11:11 am

    I have the same problem.
    I was tying to add gradient layer to navigation bar with the UIBarStyleBlackTranslucent style for glass effect. After searching the web and a lot of experiments I have not found the right solution for that problem. Finally I’ve came up with following work around:

        CAGradientLayer *yourGradient = ...
    

    // Need two additional layers to mimic UIBarStyleBlackTranslucent style

        CAGradientLayer *gradient = [CAGradientLayer layer];
    
        gradient.frame = CGRectMake(0, 0, 320, 44);
    
    
        NSMutableArray *cgColors = [[NSMutableArray alloc] init];
    
        [cgColors addObject:(id)[[UIColor colorWithRed:0.0
                                         green:0.0
                                          blue:0.0
                                         alpha:0.2] CGColor]];
        [cgColors addObject:(id)[[UIColor colorWithRed:0.0
                                         green:0.0
                                          blue:0.0
                                         alpha:0.6] CGColor]];
        [cgColors addObject:(id)[[UIColor colorWithRed:0.0
                                         green:0.0
                                          blue:0.0
                                         alpha:0.5] CGColor]];
    
        gradient.colors = cgColors;
    
        CALayer *layer = [CALayer layer];
    
        _layer.frame = CGRectMake(0, 22, 320, 22);
    
        _layer.backgroundColor =[[UIColor colorWithRed:0.0
                                                 green:0.0
                                                  blue:0.0
                                                 alpha:0.2] CGColor];
    

    // This is needed for navigation bar buttons

        [rootController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    

    // Adding layers to the first sublayer of the navigation bar layer

        [[[rootController.navigationBar.layer sublayers] objectAtIndex:0] insertSublayer:yourGradient atIndex:0];
    

    // After adding the gradient layer, the UIBarStyleBlackTranslucent style effect disappears

    // from the bar (but not from the buttons)

    // So the following is needed to mimic it

        [[[rootController.navigationBar.layer sublayers] objectAtIndex:0] insertSublayer:gradient atIndex:1];
    
        [[[rootController.navigationBar.layer sublayers] objectAtIndex:0] insertSublayer:layer atIndex:2];
    

    you may also want to add some borders to your layer as the borders seems to disappear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently adding a navigation bar to a web page. But I am
Adding strings localization files in iPhone bundle is very simple and perfectly fine but
i'm having a strange issue with banding between certain colors of a gradient. to
I have a website im working on and right now it has a gradient
I've got a header where I'm adding a little gradient spacer image, and it's
I am adding a dynamic gradient that requires multi-browser CSS; it works if directed
How to adding new colors to our gradient panel in java?
I'm trying to use the FXlabel when following this (Adding a gradient label section)
I want to try and get a cross browser gradient effect working with rgb
Adding more and more configurations to my servlet container ( Embedded Jetty in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.