iOS画图 上下文栈的使用

来源:互联网 发布:java中的构造器是什么 编辑:程序博客网 时间:2024/06/08 01:40

//

//  SCH.m

//  Contextschtest1

//

//  Created by tianshangrenjian on 15/6/29.

//  Copyright (c) 2015 tianshangrenjian. All rights reserved.

//


#import "SCH.h"


@implementation SCH



// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

    CGContextRef ctx=UIGraphicsGetCurrentContext();

    CGContextSaveGState(ctx);//入栈

    CGContextMoveToPoint(ctx,0, 0);

    CGContextAddLineToPoint(ctx,100, 100);

    CGContextAddLineToPoint(ctx,130, 80);

  //  CGContextStrokePath(ctx);

    

    CGContextSetLineWidth(ctx,40);

    

    

    CGContextSetLineJoin(ctx,kCGLineCapRound);//

    

    [[UIColorredColor ] set];

    CGContextStrokePath(ctx);

    

    

    CGContextRestoreGState(ctx);//出栈

    

    CGContextMoveToPoint(ctx,31, 10);

    CGContextAddLineToPoint(ctx,150, 170);

    CGContextAddLineToPoint(ctx,170, 180);

    //  CGContextStrokePath(ctx);

    

  //  CGContextSetLineWidth(ctx, 40);

    

    

    CGContextSetLineJoin(ctx,kCGLineCapRound);//

    

    [[UIColorblueColor ] set];

    CGContextStrokePath(ctx);

  

   NSString *str=@"kdfjdk";

    [str drawAtPoint:CGPointMake(10,100) withAttributes:nil];

    

    

    

}



@end


0 0
原创粉丝点击