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

  • SEARCH
  • Home
  • 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 6218109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:32:52+00:00 2026-05-24T07:32:52+00:00

I am using the following code to add a custom navbar to my app.

  • 0

I am using the following code to add a custom navbar to my app. But I want to be able to change the navbar depending on the view, is this possible?

@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect 
{
    UIColor *color = [UIColor colorWithRed:82/255.0 green:80/255.0 blue:81/255.0 alpha:1.0];
    UIImage *img  = [UIImage imageNamed: @"navbar.png"];
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    self.tintColor = color;
}

@end

If not, is it possible to just add an image to the navbar instead of title text?

  • 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-05-24T07:32:53+00:00Added an answer on May 24, 2026 at 7:32 am

    I would strongly discourage using a category to override -drawRect on a UINavBar as this design will break on a soon to be released iOS version.

    It is very easy to create custom images and buttons to the navBar title though. Here’s some code snippets I pulled directly out of production code for one of my apps. It creates a custom image button in the navBar’s title area, but it’s just as easy to create an image instead:

    - (void) viewDidLoad {
        UIButton *titleButton = [self buttonForTitleView];
        [titleButton setTitle:newTitle forState:UIControlStateNormal];
        [titleButton sizeToFit];
    
        self.navigationBar.topItem.titleView = titleButton;
    
    }
    
    - (UIButton *) buttonForTitleView {
        if (!_buttonForTitleView) {
            UIImage *buttonImage = [UIImage imageNamed:@"button_collection_name2"];
            UIImage *pressedButtonImage = [UIImage imageNamed:@"button_collection_name2_pressed"];
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setBackgroundImage: buttonImage forState : UIControlStateNormal];
            [button setBackgroundImage: pressedButtonImage forState : UIControlStateHighlighted];
            [button setFrame:CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height)];
            [button setTitleColor:[UIColor colorWithRed:38.0/255.0 green:38.0/255.0 blue:38.0/255.0 alpha:1.0] forState:UIControlStateNormal];
            [button setTitleShadowColor:[UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1.0] forState:UIControlStateNormal];
            button.titleLabel.adjustsFontSizeToFitWidth = YES;
            button.titleLabel.minimumFontSize = 10.0;
            button.titleEdgeInsets = UIEdgeInsetsMake(0.0, 10.0, 0.0, 10.0);
            button.titleLabel.shadowOffset = (CGSize){ 0, 1 };
            [button addTarget:self action:@selector(presentWidgetCollectionSwitchingViewController:) forControlEvents:UIControlEventTouchUpInside];
            _buttonForTitleView = [button retain];
        }    
        return _buttonForTitleView;
    }
    
    

    And this is what the button looks like in the app VideoBot:
    VideoBot custom navbar title button

    Here’s an example of using an image for the navbar title:

    UIImage  *titleImage = [UIImage imageNamed:@"navbar_title_image"];
    UIImageView *titleImageView = [[[UIImageView alloc] initWithImage:titleImage] autorelease];
    
    UIView *container = [[[UIView alloc] initWithFrame:(CGRect){0.0, 0.0, titleImage.size.width, titleImage.size.height}] autorelease];
    container.backgroundColor = [UIColor clearColor];
    [container addSubview:titleImageView];
    
    // add the view to the title
    self.navigationBar.topItem.titleView= container;
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add custom fields to an InlineFormset using the following code, but
I'm using following code but cannot return data from MySQL. This is the output:
I'm using the following code to add custom taxonomies to my menu in wordpress.
I am using the following method to add a ContextMenu to a custom view
I'm using the following code, using the SharpZipLib library, to add files to a
I add many check boxes to the excel sheet programaticaly using the following code:
Setting onchange event for CheckBoxList using the following code doesn't work. chkListUserGroup.Attributes.Add(onchange, document.forms[0].isRecordModified.value='true';); How
I'm using jQuery ui tabs with the following code but am having trouble adding
The following code shows what I want to do: public static IEnumerable<IEnumerable<T>> DoIt<T>(this IEnumerable<T>
I have added UITabButtonItem onto my view controller using following code. Could anyone please

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.