iOS 畫直線,虛線,圓,矩形畫矩形 CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetStrokeColorWithColor(ctx, [_axisColor CGColor]); CGContextSetLineWidth(ctx, 1.0); CGPoint poins[] = {CGPointMake(_margin, _margin),CGPointMake(_margin+_axisWidth, _margin),CGPointMake(_margin+_axisWidth, _margin+_axisHeight),CGPointMake(_margin, _margin+_axisHeight)}; CGContextAddLines(ctx,poins,4); CGContextClosePath(ctx); CGContextStrokePath(ctx); 畫虛線 CGPoint aPoints[2];//坐標點 aPoints[0] =CGPointMake(_margin, _margin+i*(_axisHeight/_gridStep));//坐標1 aPoints[1] =CGPointMake(_margin+_axisWidth, _margin+i*(_axisHeight/_gridStep));//坐標2 CGContextSetStrokeColorWithColor(ctx, _axisColor.CGColor); CGFloat lengths[2] = {5,5}; CGContextSetLineDash(ctx, 0, lengths, 1); //畫虛線 CGContextMoveToPoint(ctx, aPoints[0].x,aPoints[0].y); //開始畫線 CGContextAddLineToPoint(ctx, aPoints[1].x,aPoints[1].y); CGContextStrokePath(ctx); 畫圓 UIColor * color = [_colorArray objectAtIndex:_index]; CGFloat rColor,gColor,bColor,alph; [color getRed:&rColor green:&gColor blue:&bColor alpha:&alph];
/*畫圓*/ CGContextSetRGBStrokeColor(context,rColor,gColor,bColor,1);//畫筆線的顏色 CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); CGFloat lengths[2] = {5,5}; CGContextSetLineDash(context, 0, lengths, 0);//防止被虛線 CGContextSetLineWidth(context, 2.0);//線的寬度 CGFloat radius = 3;//半徑 CGContextAddArc(context, point.x, point.y,radius, 0, 2*M_PI, 0); //添加一個圓 CGContextDrawPath(context, kCGPathFillStroke); //繪制路徑//kCGPathStroke//kCGPathFill |
|