iOS Quartz2D图形上下文栈

    // 获取图形上下文

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // 存储上下文栈

    CGContextSaveGState(ctx);

    // 设置图形上下文

    CGContextSetLineWidth( ctx, 10);

    [[UIColor redColor] set];

    

    // 画第1根线

    CGContextMoveToPoint(ctx, 50, 50);

    CGContextAddLineToPoint(ctx, 200, 190);

    CGContextStrokePath(ctx);

    

    // 图形上下文栈的栈顶上下文出栈,替换当前上下文

    CGContextRestoreGState(ctx);

    

    // 画第2根线

    CGContextMoveToPoint(ctx, 10, 200);

    CGContextAddLineToPoint(ctx, 300, 50);

    CGContextStrokePath(ctx);

posted @ 2015-03-23 14:34  oumygade  阅读(116)  评论(0编辑  收藏  举报