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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:08:23+00:00 2026-05-26T04:08:23+00:00

This is probably a simple thing. I’m trying to draw my first shapes in

  • 0

This is probably a simple thing. I’m trying to draw my first shapes in my ViewDidLoad. However my context is always null, I get “con = 0x0”. I’m not sure if I’m using this properly. I’ve pasted my code below.

- (void)viewDidLoad
{
    [super viewDidLoad];

    // obtain the current graphics context

    CGContextRef con = UIGraphicsGetCurrentContext();

    // draw a black (by default) vertical line, the shaft of the arrow

    CGContextMoveToPoint(con, 100, 100);
    CGContextAddLineToPoint(con, 100, 19);
    CGContextSetLineWidth(con, 20);
    CGContextStrokePath(con);

    // draw a red triangle, the point of the arrow

    CGContextSetFillColorWithColor(con, [[UIColor redColor] CGColor]);
    CGContextMoveToPoint(con, 80, 25);
    CGContextAddLineToPoint(con, 100, 0);
    CGContextAddLineToPoint(con, 120, 25);
    CGContextFillPath(con);

    // snip a triangle out of the shaft by drawing in Clear blend mode

    CGContextMoveToPoint(con, 90, 101);
    CGContextAddLineToPoint(con, 100, 90);
    CGContextAddLineToPoint(con, 110, 101);
    CGContextSetBlendMode(con, kCGBlendModeClear);
    CGContextFillPath(con);

}

And when debugging, the value of “con” is:

con = (CGContext)0x0
  • 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-26T04:08:23+00:00Added an answer on May 26, 2026 at 4:08 am

    The problem with your code is that you are trying to draw when you are not supposed to.

    You can either move your drawing code to the drawRect: method in your view, because the operating system prepares a context into which you can draw before calling drawRect: or you can create your own context and draw into it, export it as an image and display it using an UIImageView.

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

Sidebar

Related Questions

This is probably a simple thing I'm missing, but I'm trying to get the
This is probably a really simple thing. Basically, the user clicks a button and
This is probably pretty simple, but here: Say I've got two models, Thing and
So this is probably an easy thing that I'm trying to do but I'm
This is probably a really simple thing, but I haven't been able to find
This is probably a simple thing, but ive got the following code: <div> @using
This is probably a really simple thing, but I don't know how to implement
This is probably a fairly simple thing to do - I have a site
This is probably some thing very simple and I tried a couple of things
I know this probably really simple but Im not sure what im doing wrong...

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.