绘制三角形矩形

 /**绘制三角形*/
    CGContextRef contextRef=UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(contextRef, 100, 100);
    CGContextAddLineToPoint(contextRef, 100, 200);
    CGContextAddLineToPoint(contextRef, 200, 200);
    
    CGContextMoveToPoint(contextRef, 100, 100);
    CGContextAddLineToPoint(contextRef, 200, 200);
    CGContextSetStrokeColorWithColor(contextRef, [UIColor redColor].CGColor);
    CGContextStrokePath(contextRef);
    
     
    /**绘制矩形*/
    CGContextRef contextRef=UIGraphicsGetCurrentContext();
    CGContextAddRect(contextRef, CGRectMake(50, 100, 200, 200));
    CGContextSetRGBFillColor(contextRef, 1, 0, 0, 1.0);
    CGContextFillPath(contextRef);
    
    /**绘制矩形*/
    CGContextMoveToPoint(contextRef, 100, 100);
    CGContextAddLineToPoint(contextRef, 200, 100);
    CGContextMoveToPoint(contextRef, 100, 100);
    CGContextAddLineToPoint(contextRef, 100, 200);
    CGContextMoveToPoint(contextRef, 100, 200);
    CGContextAddLineToPoint(contextRef, 200, 200);
    CGContextMoveToPoint(contextRef, 200, 100);
    CGContextAddLineToPoint(contextRef, 200, 200);
    CGContextStrokePath(contextRef);
    
原文地址:https://www.cnblogs.com/thbbsky/p/4382187.html