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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:27:59+00:00 2026-05-26T12:27:59+00:00

I would like to set an image as UINavigationController background but most solutions I

  • 0

I would like to set an image as UINavigationController background but most solutions I found apply background in navigation bar for all views in the app. Can you give some code that may help ?

Thx for helping,

Stephane

  • 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-26T12:27:59+00:00Added an answer on May 26, 2026 at 12:27 pm

    Here’s a quick and dirty way that I use in one of my projects (I have no need to support landscape orientation). I implemented it with a category to UINavigationBar with method swizzling. Works on iOS 4 and 5 (I didn’t try it on iOS 3).

    UINavigationBar+SYCustomBackground.h

    #import <UIKit/UIKit.h>
    
    @interface UINavigationBar (SYCustomBackground)
    @property (nonatomic,retain) UIImage *sy_customBackgroundImage;
    @end
    

    UINavigationBar+SYCustomBackground.m

    #import "UINavigationBar+SYCustomBackground.h"
    #import <objc/runtime.h>
    
    @implementation UINavigationBar (SYCustomBackground)
    
    static char BACKGROUND_IMAGE_KEY;
    static BOOL drawRectsSwizzled = NO;
    
    // Swizzles drawRect: and sy_drawRect:
    - (void)swizzleDrawRectIfNecessary
    {
        if (!drawRectsSwizzled) {
            Method origMethod = class_getInstanceMethod([self class], @selector(drawRect:));
            Method myMethod = class_getInstanceMethod([self class], @selector(sy_drawRect:));
            method_exchangeImplementations(origMethod, myMethod);
            drawRectsSwizzled = YES;
        }
    }
    
    - (void)setSy_customBackgroundImage:(UIImage *)image
    {
        // iOS 5
        if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
            [self setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
        }
        // iOS < 5
        else {
            [self swizzleDrawRectIfNecessary];
            objc_setAssociatedObject(self, &BACKGROUND_IMAGE_KEY, image, OBJC_ASSOCIATION_RETAIN);
        }
    }
    
    - (UIImage *)sy_customBackgroundImage
    {
        // iOS 5
        if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
            return [self backgroundImageForBarMetrics:UIBarMetricsDefault];
        }
        // iOS < 5
        else {
            [self swizzleDrawRectIfNecessary];
            return objc_getAssociatedObject(self, &BACKGROUND_IMAGE_KEY);
        }
    }
    
    - (void)sy_drawRect:(CGRect)rect
    {
        UIImage *backgroundImage = self.sy_customBackgroundImage;
    
        if (backgroundImage) {
            [backgroundImage drawInRect:rect];
        }
        else {
            // No custom image, calling original drawRect:
            // Note: it’s swizzled, so we must call sy_drawRect:
            [self sy_drawRect:rect];
        }
    }
    
    @end
    

    Then you set your background images in viewWillAppear and restore them in viewWillDisappear if you want to change images in one UINavigationController.

    It’s not perfect, I would add some crossfade transition, add push/pop for backgrounds, but I have no time yet, so feel free to improve it.

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

Sidebar

Related Questions

I would like to set an image background to the navigation bar on my
I would like to set background image or a list item when selected or
I would like to use an image as background. Unfortunately, when I set the
I would like to programmatically set an image to the background of each cell
I would like to know if it's possible to set an image as background
i would like to set the date format of all the dates in my
I would like to set up a lean and mean image gallery, with thumbnails
I would like to set the background of a cell in HTML table to
I would like to know if I can make an image opaque if set
I would like to set not square image to square and use for this

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.