Assignment #3 Task #5

Please note, this blog entry is from a previous course. You might want to check out the current one.

To implement your new MVC, you must write a custom graphing View which must display the axes of the graph in addition to the plot of the program. Code will be provided on the class website which will draw axes with an origin at a given point and with a given scale, so you will not have to write the Core Graphics code for the axes, only for the graphing of the program itself. You probably will want to examine the provided axes-drawing code to understand how the scaling works before you do this or any of the following Required Tasks.

The mentioned code is available for download at Stanford. Add it to your project and create a new view class e.g. GraphView as subclass from UIView.

Inside your storyboard add a new generic view, change its class to your newly created GraphView class and create a property to get access in your controller.

Finally, we draw the axis with fixed values:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();    
    [[UIColor grayColor] setStroke];
    CGRect area = self.bounds;
    CGFloat scale = 50.0;
    CGPoint origin;
    origin.x += area.size.width / 2;
    origin.y += area.size.height / 2;
    [AxesDrawer drawAxesInRect:area originAtPoint:origin scale:scale];
    CGContextStrokePath(context);
}    
FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.