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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:37:51+00:00 2026-06-03T07:37:51+00:00

Aim: my UINavigationBar has to be customized with a certain background and a specific

  • 0

Aim: my UINavigationBar has to be customized with a certain background and a specific label font.

This is easily achievable in iOS5 with the appearance protocol. Ok.

What if my user runs < iOS5? He will see default UINavigationBar, but not if I extend UINavigationBar with a category that overrides drawRect.

Question 1: How can I specify in my Prefix.pch a conditional #import of UINavigationBar category extension according to iOS version?

Question 2: Assuming I manage to solve question 1, will this work? I mean, if the device is not iOS5 I am NOT setting [UINavigationBar] appearance] but only importing the category, do I need to do something more?

EDIT: This is the implementation of Vladimir suggestion, I don’t have a iOS4 device nor simulator to test it right now but I think it might work.

@implementation UINavigationBar (iOS4Appearance)

- (void)drawRect:(CGRect)rect 
{
    if (self.isiOS5) {
        [super drawRect];
    } else {
        UIImage *background = [UIImage imageNamed: @"navigation-bar"];
        [background drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    }
}

- (BOOL)isiOS5
{
    return [[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0;
}

@end

Thanks for any help.

  • 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-03T07:37:52+00:00Added an answer on June 3, 2026 at 7:37 am

    I don’t think you can do this with #import, since that’s compile-time, and you can only upload one binary to the app store (which should be iOS-version-independent). Instead, you can test this at runtime. For example, you can override drawRect, but depending on the iOS version you’ll either call super or run your own code.

    EDIT:

    My suggestion won’t work with plain categories because they replace the original implementation. There are at least two alternatives:

    1. Subclassing UINavigationBar and overriding drawRect.
    2. Method swizzling the drawRect on existing UINavigationBar instances.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My aim is to disable usb port usage except a specific kind of usb.
My aim is have the text inside this div displaying in the middle of
my aim is to reverse an array 3,12,2,1 to 1,2,12,3. when i run this
My aim is to create an application whereby a user can drag a label
My aim is to get a json array like this one: var args =
My aim is to implement the Single Log Out Protocol. First I am understanding
My aim was to change the background image and set it's SizeMode as Stretch.
Aim :- to set background image in my application that fills the device both
My aim before writing this code was to just practice and learn more about
I aim to make an app that would store sms messages with certain words

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.