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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:21:36+00:00 2026-06-15T19:21:36+00:00

Why doesn’t this work? I want to sublcass UINavigationBar so in xcode I click

  • 0

Why doesn’t this work? I want to sublcass UINavigationBar so in xcode I click new file -> objective c class,
class: CustomNavBar
subclass of: UINavigationBar

then in the storyboard under the navigation controller scene, I click on the Navigation Bar and set it’s class to CustomNavBar.

I then go into my CustomNaVBar class and have tried to add a custom image background.

In the initWithFram method I have added this:

- (id)initWithFrame:(CGRect)frame
{
    NSLog(@"Does it get here?"); //no
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        UIImage *image = [UIImage imageNamed:@"customNavBarImage.png"];
        //  [self setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
        [self setBackgroundColor:[UIColor colorWithPatternImage:image]];
        [[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
        NSLog(@"Does this get called?"); //no
    }
    return self;
}

I don’t see any output on the console.

Instead I have done this to customize the UINavBar, but I feel like it isn’t as correct as sublassing it. In my first view’s viewDidLoad I added this line:

- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        UIImage *image = [UIImage imageNamed:@"customNavBarImage.png"];
        [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    }
}
  • 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-15T19:21:37+00:00Added an answer on June 15, 2026 at 7:21 pm

    I agree with Ryan Perry. In addition to his answer:

    You should not put this code in initWithFrame, instead put your code in awakeFromNib

    - (void) awakeFromNib {
        // Initialization code
        UIImage *image = [UIImage imageNamed:@"customNavBarImage.png"];
        //  [self setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
        [self setBackgroundColor:[UIColor colorWithPatternImage:image]];
        [[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
        NSLog(@"Does this get called?"); //YES!!
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't this work? The label is inside the .item parent. I don't want
This doesn't work: int number = 1; String numberstring = IntToString(number); I get The
Why doesn't this code work? b if b = true Error: undefined local variable
Why doesn't this work? Some Usercontrol (name: myUserControl) with an image control (name: myImage):
Why doesn't this test case work? <?php // cards with cyrillic inidices and suits
This doesn't work. I've got an exception from SQL databse that column does not
This doesn't work: create table event ( ... time int default date_part('epoch', timestamp 'now'),
This doesn't work, it turns it to gibberish: $foo = 'נ'; $bar = mb_convert_encoding($foo,
This doesn't work: if(document.getElementById(iframe).innerHTML==''){ Is there a safe browser reliable way to check an
Why doesn't this work? find . -maxdepth 1 -type f -print0 | xargs -0

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.