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 8075555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:01:14+00:00 2026-06-05T15:01:14+00:00

I was trying to implement a project with custom navigation bar; however, the following

  • 0

I was trying to implement a project with custom navigation bar; however, the following code:

@implementation UINavigationBar (CustomImage)

// Set the navigation bar background
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed:@"TopBar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height + 1)];
}
@end

is not working for iOS 5. I am using Xcode 4.2.

Question: How can I implement a custom navigation bar without compromising the use of the code above for earlier versions (< iOS 5)?

Any help would be appreciated. 🙂

  • 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-05T15:01:17+00:00Added an answer on June 5, 2026 at 3:01 pm

    I finally got it…this might help others implementing this.

    @implementation UINavigationBar (CustomImage)
    
    // Set the navigation bar background
    - (UIImage *)barBackground{
        UIImage *image = [UIImage imageNamed:@"TopBar.png"];
        [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height + 1)];
        return image;
    }
    
    - (void)didMoveToSuperview{
        // Applies to iOS 5
        if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
        {
            [self setBackgroundImage:[self barBackground] forBarMetrics:UIBarMetricsDefault];
        }
    }
    
    // This doesn't work on iOS5 but is needed for iOS4 and earlier
    - (void)drawRect:(CGRect)rect
    {
        // Draw the image
        [[self barBackground] drawInRect:rect];
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement ServiceStack into my MVC3 project, and am following the tutorial
I am trying to implement Custom Error handling via Action Filter Attributes. My code
I'm trying to implement the following code in a html document: $(function () {
I am currently trying to implement a Custom Configuration Section in a project I
I'm trying to implement code-completion popup window in my project. The window is derived
Im trying to implement small project where people can set tags for certain items
I am trying to implement openssl code I found into my project but I
I'm trying to implement the code below in my WPF project in order to
I've been trying to implement a custom ORM for our project and am interested
I am trying to implement a custom configuration section in a project and I

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.