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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:08:32+00:00 2026-06-03T07:08:32+00:00

I am trying to draw a graph which moves up and down depending on

  • 0

I am trying to draw a graph which moves up and down depending on the value of a slider.
My graph is being drawn in a view which belongs to a custom class GraphView.
There is one ViewController for the project and the slider calls a method moveLine.
This has a property endXPoint which I have set such that:
endXPoint = mySlider.value

My problem is that I don’t know how to reference this value from inside the drawRect method of my GraphView.

I have tried creating a reference to GraphView in the ViewController and setting the property there but it does not work:
GraphView *myGraphView = (GraphView *)self.view;
myGraphView.endXPoint = mySlider.value;

  • 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-03T07:08:33+00:00Added an answer on June 3, 2026 at 7:08 am

    You have to set a property for the GraphView class like that:

    @interface GraphView : UIView
    @property float endXPoint;
    

    Then from the ViewController you set the GraphView variable like:

    [myGraphView setendXPoint: [mySlider value]];
    [myGraphView setNeedsDisplay];
    

    The last line ask GraphView to update the View, calling the drawRect method.
    In the drawRect method you can use endXPoint directly because it is a class property.

    This is the correct version:

    //ViewController.h
    
    #import <UIKit/UIKit.h> 
    #import "GraphView.h" //import headers in the header file
    
    @interface ViewController : UIViewController  
    
    @property (strong, nonatomic) IBOutlet UISlider *mySlider;  
    @property (strong, nonatomic) IBOutlet UILabel *myLabel;  
    @property (strong, nonatomic) IBOutlet GraphView *myGraphView; //Connect this with the IB
    
    - (IBAction)moveLine:(id)sender; 
    - (IBAction)setLabelText:(id)sender;  
    @end  
    
    //ViewController.m
    
    #import "ViewController.h"   
    
    @implementation ViewController  
    @synthesize mySlider;  
    @synthesize myLabel;  
    @synthesize myGraphView;
    
    
    
    - (IBAction)moveLine:(id)sender {  
        [myGraphView setendXPoint:[mySlider value]];  
        [myGraphView setNeedsDisplay];  
    }  
    
    @end 
    
    //GraphView.h 
    
    #import <UIKit/UIKit.h>  
    
    @interface GraphView : UIView  
    @property float endXPoint;  
    
    
    @end
    
    //GraphView.m  
    
    #import "GraphView.h"   
    
    @implementation GraphView  
    @synthesize endXPoint;  
    
    
    - (void)drawRect:(CGRect)rect  
    {
    
        CGContextRef ctx = UIGraphicsGetCurrentContext(); //get the graphics context  
        CGContextSetRGBStrokeColor(ctx, 1.0, 0, 0, 1);   
        CGContextMoveToPoint(ctx, 0, 0);  
        //add a line from 0,0 to the point 100,100;   
        CGContextAddLineToPoint( ctx, endXPoint,100);  
        //"stroke" the path  
        CGContextStrokePath(ctx);  
    }  
    
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw a simple line graph which would use values from the
I am trying to draw a graph showing search prefixes using twopi. I have
I am trying to plot graph in which i want to fill graph area
I am trying to draw a graph using Graphviz, but I need to add
i'm trying to draw a Graph with a user-friendly timeline having every day/week (to
Hi I am trying to draw one line graph and for that I am
I was trying a script to draw graph paper like grids on the canvas
I'm trying to draw a graph of the dependencies between C header files using
The task is, to draw paths at runtime on custom maps which im using
I am trying to draw a graph of some data I pull out of

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.