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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:57:24+00:00 2026-05-21T23:57:24+00:00

I want to draw on a UIView that has a background image that I

  • 0

I want to draw on a UIView that has a background image that I set using the code below:

- (void)setBackgroundImageFromData:(NSData *)imageData {
    UIImage *image = [UIImage imageWithData:imageData];

    int width = image.size.width;
    int height = image.size.height;
    CGSize size = CGSizeMake(width, height);

    CGRect imageRect = CGRectMake(0, 0, width, height);

    UIGraphicsBeginImageContext(size);
    CGContextRef currentContext = UIGraphicsGetCurrentContext();

    CGContextTranslateCTM(currentContext, 0, height);
    CGContextScaleCTM(currentContext, 1.0, -1.0);

    CGContextDrawImage(currentContext, imageRect, image.CGImage);

    UIGraphicsEndImageContext();
}

The initial view is created using the code from Apple’s GLPaint example. For the life of me, that background image is not shown. What am I missing?

Thanks!

  • 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-21T23:57:25+00:00Added an answer on May 21, 2026 at 11:57 pm

    You create a UIImage, and an imageRect successfully. You then begin a image context to draw the image to, draw the image to the context, and end the context. The problem is that you just allow the context to expire without doing anything to it.

    In UIKit you don’t push new visuals upwards, you wait until requested to draw. Internal mechanisms cache your images and use them to move things about and otherwise redraw the screen at the usual 60fps.

    If this is a custom UIView subclass, then you probably want to keep hold of the UIImage and composite it as part of your drawRect:. You can set the contents of your UIView as having changed by calling setNeedsRedraw — you’ll then be asked to redraw your contents at some point in the future.

    If this isn’t a custom subclass, then the easiest thing to do is to wrap this view in an outer view and add a UIImageView behind it, to which you can set the UIImage.

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

Sidebar

Related Questions

I want to draw text into UIView 's subview using drawInRect:withFont:lineBreakMode call but that
I want to draw markers on a zoomable UIView that's using UIScrollView and CATiledLayer.
I have a custom UIView that draws an image in the draw rect method.
I made of subclass of UIView called Bubble using which i want to draw
I have a subclass of UIView that implements code to draw CoreText. In the
I want to make a section which has an image and some text below
I want to draw my opengl es animation in a customed UIView, how can
For example, I want to draw something directly to an UIView. I need an
I want to draw some Rectangle over a single Image . For example I
I want to draw rectangle that is only specified percent high of panel im

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.