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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:42:54+00:00 2026-05-30T05:42:54+00:00

I wanted to draw a line using CGContext and what I have so far

  • 0

I wanted to draw a line using CGContext and what I have so far is:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 1.0f);
CGContextMoveToPoint(context, 10, 10); 
CGContextAddLineToPoint(context, 100, 50);
CGContextStrokePath(context);

It always draws from the top left corner to the top bottom right corner. How can I adjust the start and end origin of this line? How do I adjust the length of the line?

  • 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-30T05:42:56+00:00Added an answer on May 30, 2026 at 5:42 am

    These two lines are responsible for the start and end points:

    CGContextMoveToPoint(context, 10, 10);    // This sets up the start point
    CGContextAddLineToPoint(context, 100, 50); // This moves to the end point.
    

    By adjusting these two x, y points you can adjust the line. The length of the line depends on the start and end points.

    Following on from psoft’s answer – here’s a basic example project of drawing, including creating a path and stroking it.

    This is explained in more detail with more sample code in the Quartz 2D guide for paths.

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

Sidebar

Related Questions

If I wanted to draw arrows instead of axis lines using one of the
I wanted to make a class Draw which will have static method ConsoleSquare() and
I have recently been thinking alot about where to draw the line, and I
I draw a triangle using mouse drag. After drawing many different triangles, I wanted
I have a generic question about tableview Draw and reload data, and wanted some
I wanted to generate one fix view using interface builder, but the size of
I'm developing a Facebook app which allow my users to draw their wanted path
I wanted to paint my own version of JButton, so I have overridden the
I need to draw an arc using GraphicsPath and having initial, median and final
I wanted to draw special characters like this one ( http://www.fileformat.info/info/unicode/char/2605/index.htm ) in JLabel.

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.