Quartz2D绘制字体和图形

//

//  CJWView.m

//  

//

//  Created by CJW on 16/7/13.

//  Copyright © 2016 ch. All rights reserved.

//


#import "CJWView.h"


@implementation CJWView



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

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    //取得和当前视图相关联的图形上下文

     NSString * cjw_str =@"付好了发的发觉fklfsdkf发送的开发了奥斯卡发顺丰阿斯蒂芬卢萨卡法拉盛卡夫卡的沙拉和反馈萨拉弗利萨发送发送付了款;傲世发是否傲世";

    

    CGContextRef   ctx =UIGraphicsGetCurrentContext();

    CGContextAddRect(ctx,CGRectMake(50,50,100, 100));

    CGContextStrokePath(ctx);

    

//    NSMutableDictionary *md = [NSMutableDictionary dictionary];

//    // 设置文字颜色

//    md[NSForegroundColorAttributeName] =[UIColor redColor];

//    // 设置文字背景颜色

//     md[NSBackgroundColorAttributeName] = [UIColor greenColor];

//     // 设置文字大小

//     md[NSFontAttributeName] = [UIFont systemFontOfSize:20];

//    [cjw_str drawAtPoint:CGPointMake(10, 10) withAttributes:md];

    

    //    将文字绘制到指定的范围内,如果一行装不下会自动换行,当文字超出范围后就不显示

    [cjw_str drawInRect:CGRectMake(50,50,100, 100withAttributes:nil];

    


    /**

     *  画矩形和圆

     *

    */

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    //    旋转,必须在绘图之前

    //注意点:设置矩阵操作必须要在添加绘图信息之前

    //    CGContextRotateCTM(ctx, M_PI_4);

    //绘图(矩形)

    

    //注意点:设置矩阵操作必须要在添加绘图信息之前

    //缩放,x方向缩放0.5倍,y方向缩放1.5

    CGContextScaleCTM(ctx, 0.5, 1.5);

    

    CGContextAddRect(ctx, CGRectMake(150, 50, 100, 100));


    //画圆

    CGContextAddEllipseInRect(ctx, CGRectMake(150, 100, 50, 50));

    //渲染

    CGContextStrokePath(ctx);


    

    //  1.加载图片到内存中
    //UIImage *image = [UIImage imageNamed:@"me"];
     
  
    // 利用OC方法将图片绘制到layer上
    
    // 将图片绘制到指定的位置
    // [image drawAtPoint:CGPointMake(100, 100)];
  }

    

    

}



@end































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值