分享

iOS 画直线,虚线,圆,矩形

 quasiceo 2015-06-22

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



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约