//
// 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, 100) withAttributes: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