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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:57:10+00:00 2026-05-26T16:57:10+00:00

I use a custom background image for my navigation bar. So in my app

  • 0

I use a custom background image for my navigation bar. So in my app delegate I set:

UIImage *image1 = [UIImage imageNamed:@"mh.png"];

[image1 drawInRect:CGRectMake(0, 0, 480, 320)]; 
[[UINavigationBar appearance] setBackgroundImage:image
                              forBarMetrics:UIBarMetricsDefault];

But this gives me a bunch of errors like

Wed Nov  2 23:05:36 My-MacBook.local MessageDJ[480] <Error>: CGContextScaleCTM: invalid context 0x0
Wed Nov  2 23:05:36 My-MacBook.local MessageDJ[480] <Error>: CGContextDrawImage: invalid context 0x0
Wed Nov  2 23:05:36 My-MacBook.local MessageDJ[480] <Error>: CGContextRestoreGState: invalid context 0x0

Any idea why this happens and how to fix it?

  • 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-26T16:57:11+00:00Added an answer on May 26, 2026 at 4:57 pm

    You don’t need the drawInRect method call to set the image, however for completeness sake I will explain why your code is generating errors….

    The UIImage drawInRect method is a UIKit helper method which wraps up some QuartzCore calls to draw an image; it flips the context before drawing so the image appears the correct way up for example. The problem with your code is that there is no graphics context currently set for these underlying calls to work on.

    First you need a valid graphics context, so you need one of the UI Graphics context calls…

    UIGraphicsBeginImageContext
    UIGraphicsBeginPDFContextToFile
    UIGraphicsBeginPDFContextToData
    

    or if you are currently in a drawRect call you can get the current context by using…

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

Sidebar

Related Questions

I use the TTLauncherView in my project. To have a custom navigation bar background
My app has a custom background for the navigation bar. So i made a
I've seen some iPhone applications that use a custom image as the background for
I have customised my SeekBar - I use a custom image as the background,
Is there any way to have a custom-shape image container? To use something instead
I wanted to use a custom background for my UITextFields . This works fine
I want to add a background image for some labels in my custom view.
In order to set a background image for my Desktop Flex application, I created
I'm having a little problem with customising an app's navigation bar and using an
I want to add a custom button (to the right) in my navigation bar.

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.