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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:01:37+00:00 2026-05-20T23:01:37+00:00

I want to draw a line(on iphone) such that i can view each pixel

  • 0

I want to draw a line(on iphone) such that i can view each pixel being draw.

I am currently calling the drawRect method using a timer.

Following is the code where i am drawing a wave using the values from an array:

static int i=0;
int x = 10;
int y = 0;
int x2;
int y2;

- (void)drawRect:(CGRect)rect 
{
// Drawing code.
CGContextRef c = UIGraphicsGetCurrentContext();

CGFloat black[4] = {0.0f,0.0f,0.0f,1.0f};
CGContextSetStrokeColor(c, black);
CGContextBeginPath(c);
NSLog(@"fired...");
int ecg[358] = {36, 37, 37, 36, 34, 33, 33, .... ,36}; //Assume the data is there

CGContextMoveToPoint(c, x, y);

x2 = i;
y2 = ecg[i];
CGContextAddLineToPoint(c, x2, y2);
x = x2;
y = y2;

CGContextStrokePath(c); 
[self setNeedsDisplay];
i++;
}

- (void) awakeFromNib
{
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(drawRect:) userInfo:nil repeats:YES];
}

I can only see one line at a time being draw when drawRect is called. But i dont see the entire image. I cannot think of a different approach in order to see the wave being draw on the screen.

Also the method initWithFrame is never called so had to go with awakeFromNib to declare the timer, correct me if i am wrong.

Any pointers to animate the drawing of a line would help.

Thank you

  • 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-20T23:01:37+00:00Added an answer on May 20, 2026 at 11:01 pm

    Just re-draw the stuff up to the point that you want, like:

        for (int j = 0; j <= i; j++) {
            x2 = j;
            y2 = ecg[j];
            CGContextAddLineToPoint(c, x2, y2);
            x = x2;
            y = y2;
        }
    
        CGContextStrokePath(c); 
    

    Do not call setNeedsDisplay: in your drawRect:, it causes the view to be redrawn immediately afterwards over and over again. Also, try to avoid global variables. For examples, there’s no need to “cache” x, x2, y and y2 here. Define them inside drawRect:.

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

Sidebar

Related Questions

I want to draw line in table view cell so that I can place
I want to draw a line in Crystal report. I can do that from
I want to draw line on iPad using user points. How can I do
I want to draw line on image view then image view is to put
I want to draw a simple line on the iPhone by touching and dragging
I want draw a line between to specify point in java 3d. how can
I want to draw 10 by 10 grid that defines ground plane such that
I want to draw DirectX content so that it appears to be floating over
How can i draw a box in css? I want a box like the
I want to draw line on UIImageView. I already draw line on UIImageView but

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.