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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:35:57+00:00 2026-06-13T11:35:57+00:00

in my application, I have a view named mainvie – when the application runs,

  • 0

in my application, I have a view named mainvie – when the application runs, mainview is loaded which loads a background image onto the screen ( code below) ring_large.jpg has been added as a file.

- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed:@"rink_large.jpg"];
CGPoint imagepoint = CGPointMake(10,0); 
[image drawAtPoint:imagepoint];
}

This works fine, it is when I am trying to draw another image on top of this that I am having issues. Elsewhere (file named mainviewcontroller.m) – On a touch even I am trying to get the location of the touch, and draw an image at the location. Listed below is my code. I am not sure why the image I am trying to place is not drawing at all. I am sure it is not drawing behind the rink image, as i commented this out and the image still doesnt draw when clicked. Here is the touches begin function which should draw the image.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     CGPoint location = [[touches anyObject] locationInView:mainView];
    UIImage *image = [UIImage imageNamed:@"small_cone.png"];
    [image drawAtPoint:location];
}

Can anyone see why the image will not draw when somewhere is touched? The touchesBegan function start when the screen is touched anywhere, but the picture is not displaying. Thanks for your help, I am newer to objective – c.

  • 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-13T11:35:58+00:00Added an answer on June 13, 2026 at 11:35 am

    UIImage drawAtPoint draws the image within the current graphics context. You are not defining a graphics context. In drawRect (where your original code is) there is already a graphics context. Basically, you are telling the UIImage what location to draw at, but not what to draw on.

    You need something more like this:

    CGPoint location = [[touches anyObject] locationInView:mainView];
    
    UIGraphicsBeginImageContext(mainView.bounds.size);
    UIImage *image = [UIImage imageNamed:@"small_cone.png"];
    [image drawAtPoint:location];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    However, this won’t preserve or take into account your original image. If you want them both drawn, one over the other, use drawAtPoint for both images:

    CGPoint location = [[touches anyObject] locationInView:mainView];
    
    UIGraphicsBeginImageContext(mainView.bounds.size);
    
    UIImage *image = [UIImage imageNamed:@"rink_large.jpg"];
    CGPoint imagepoint = CGPointMake(10,0);
    [image drawAtPoint:imagepoint];
    
    image = [UIImage imageNamed:@"small_cone.png"];
    [image drawAtPoint:location];
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    Now you can do something with newImage, which contains a composite of both images.

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

Sidebar

Related Questions

In my WPF+MVVM application I have a View which hosts another usercontrol. The child
I have an application, which will have a view layer organized in three parts:
I have a Backbone view named Foo which has a scrollbar. When the scrollbar
In my viewbased application i loaded oneview as mainview and another view as subview
I have application where i have two view controllers my first view and second
In my application,i have text view with long text. i need text wrapping like
In my WPF application I have a View that is given a ViewModel, and
In an MVC3 application I have a view rendering two Ajax partial views: a
In my Backbone application I have a main view that shows previews of posts.
hai all, in my iphone application i have a login view with two text

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.