I'm working on the extra credit of assignment 3 on Stanford's app development class. I'm trying to do the part where you use a segmented control to choose solid or dashed lines. I added an outlet for the segmented control to my view controller. When the value of the control is changed, it calls this method in the controller:
and here is my drawRect:
For some reason, it always draws solid lines and never dashed ones. The code for dashed lines is never run because "dashed" never shows up in the console. Any ideas?
Code:
-(IBAction)segmentedControlLineTypeChanged{
[polyView setNeedsDisplay];
}
Code:
//set up the path
CGContextClosePath(context);
[[UIColor blackColor]setStroke];
[[UIColor yellowColor]setFill];
CGContextSetLineWidth(context, 2);
if (segmentedControlLineType.selectedSegmentIndex == 0) {
//draw solid lines
NSLog(@"solid");
}
if (segmentedControlLineType.selectedSegmentIndex == 1) {
//draw dashed lines
float lengths[2] = {10, 10};
CGContextSetLineDash(context, 0, lengths, 1);
NSLog(@"dashed");
}
CGContextDrawPath(context, kCGPathFillStroke);