Quartz 2D绘图

- (void)drawRect:(CGRect)rect {

    

    CGContextRef content = UIGraphicsGetCurrentContext();

    

    //1.绘制图画

//    [self drawImage:content];

    

    //2.绘制文字

//    [self drawtext:content];

    

    //3.绘制贝塞尔曲线

//    [self drawCure:content];

    

    //4.绘制圆弧

    [self drawArc:content];

}


#pragma mark - 绘制图画

- (void)drawImage:(CGContextRef)content {

    UIImage *image = [UIImage imageNamed:@"2012100413195471481.jpg"];

    

    //转换坐标

    CGContextSaveGState(content);

    CGContextRotateCTM(content, M_PI);

    CGContextScaleCTM(content, -1, 1);

    CGContextTranslateCTM(content, 0, -self.bounds.size.height);

    

    CGContextDrawImage(content, self.bounds, image.CGImage);

    

    CGContextRestoreGState(content);


}


#pragma mark - 绘制文字

- (void)drawtext:(CGContextRef)content {

    NSString *str = @"哈哈哈";

    

    CGRect rect = CGRectMake(50, 50, 200, 200);

    [[UIColor redColor] setFill];

    UIRectFill(rect);

    

    CGRect rect1 = CGRectMake(200, 50, 200, 200);

    [[UIColor orangeColor] setFill];

    UIRectFill(rect1);

    

    

    UIFont *font = [UIFont systemFontOfSize:20];

    [str drawInRect:rect withAttributes:@{NSFontAttributeName:font}];

    

    

}


#pragma mark - 绘制贝塞尔曲线

- (void)drawCure:(CGContextRef)context {

    CGContextSetLineWidth(context, 5);

    [[UIColor redColor] setStroke];

    

    CGContextMoveToPoint(context, 20, 100);

    

    CGContextAddCurveToPoint(context, 100, 20, 200, 300, 300, 50);

    

    CGContextDrawPath(context, kCGPathStroke);

}


#pragma mark - 绘制圆弧

- (void)drawArc:(CGContextRef)context {

    

    //转换坐标

    CGContextSaveGState(context);

    CGContextRotateCTM(context, M_PI);

    CGContextScaleCTM(context, -1, 1);

    CGContextTranslateCTM(context, 0, -self.bounds.size.height);

    

    [[UIColor grayColor] setFill];

    [[UIColor redColor] setStroke];

    CGPoint centerPoint = CGPointMake(150, 150);

    float radius = 100;

    CGFloat beginAngle = 0;

    CGFloat endAngle = M_PI_4;

    CGContextAddArc(context, centerPoint.x, centerPoint.y, radius, beginAngle, endAngle, 1);

    

    CGContextMoveToPoint(context, centerPoint.x+radius*cos(beginAngle), centerPoint.y+radius*sin(beginAngle));

    CGContextAddLineToPoint(context, centerPoint.x, centerPoint.y);

    CGContextAddLineToPoint(context, centerPoint.x+radius*cos(endAngle), centerPoint.y+radius*sin(endAngle));

    

    CGContextDrawPath(context, kCGPathEOFillStroke);

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值