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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:06:17+00:00 2026-05-30T18:06:17+00:00

I want to create a CGPath to look like a trail in an overview

  • 0

I want to create a CGPath to look like a trail in an overview perspective. I have the following code in a UIView subclass. I know I am entering the methods through NSLogs. The CGPath doesn’t appear on the screen.

- (void)drawRect:(CGRect)rect{
  CGMutablePathRef p = CGPathCreateMutable();
  CGPathMoveToPoint( p, NULL , 150 , 150 );
  CGPathMoveToPoint( p, NULL , 300 , 300 );
  CGPathMoveToPoint( p, NULL , 100 , 150 ) ;
  CGPathMoveToPoint( p, NULL , 150 , 150 );
  CGPathAddLineToPoint( p, NULL , 300 , 300 );
  CGPathAddLineToPoint( p, NULL , 100 , 150 ) ;
  CGPathAddLineToPoint( p, NULL , 150 , 150 );

  CGPathCloseSubpath( p ) ;

  CGContextRef context=UIGraphicsGetCurrentContext(); 
  CGContextBeginPath(context);
  CGContextAddPath ( context, p ) ;
  CGContextSaveGState(context); 

  CGColorRef redColor = [UIColor colorWithRed:1.0 green:12.0 blue:0.0 alpha:0.0].CGColor;
  CGContextSetFillColorWithColor(context, redColor);
  CGContextSetLineWidth(context, 20.0);
  CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

  CGContextStrokePath(context);
  CGContextFillPath ( context ) ;

  CGContextDrawPath(context, kCGPathFill);
  CGContextRestoreGState(context);
}

Nothing shows up
In advance 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-30T18:06:18+00:00Added an answer on May 30, 2026 at 6:06 pm

    The frameworks ensure that in -drawRect: there is already an appropriate graphics context set up for you and pointed at the display device. You only need UIGraphicsBeginImageContext()/UIGraphicsEndImageContext() if you are setting up to render someplace else, such as to an image.

    Delete those calls and things will behave a lot better. Right now you are rendering to an off-screen buffer, not to the view itself.

    Edit: You should, however, add a pair of CGContextSaveGState() / CGContextRestoreGState() calls around your code, however. This will ensure you don’t contaminate the graphics context for other graphics code if your -drawRect: is used in certain ways.

    Edit 2: Alright, I see that you have resolved the issue after your last response, but for the benefit of archives, I am going to point out that you never call -drawRect: directly (except in some obscure cases that don’t apply here). Since you had called it directly, no graphics context had been set up, hence the crash. The proper way to trigger redraw is to send the view -setNeedsDisplay; this will cause the frameworks to setup a graphics context and invoke -drawRect: for you at the appropriate time in the run loop.

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

Sidebar

Related Questions

I have a UIView that I draw a CGPath to and would like to
I want create subdomains like this: domain.com/type/city An examples: domain.com/restaurants/new_york domain.com/hotels/new_york domain.com/restaurants/chicago I have
I have following string. $option = '+'; $value = '100'; I want create new
i want create XML file here is my following code String fileName = jasstech.xml;
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
i want create image animation , i have 50 images with png format now
In C# code, I want create a log file for each each method in
I want create something that looks like the MSN Messenger chat forms. I am
I want create object from Canvas3D class(in java) but my Compiler doesn't have this
i want create a screen for entering Sales Order details. i want to fasten

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.