NSFont
*font = [
NSFont
fontWithName:@
"Palatino-Roman"
size:14.0];
NSDictionary
*attrsDictionary = [
NSDictionary
dictionaryWithObject:font
forKey:
NSFontAttributeName
];
NSAttributedString
*attrString = [[
NSAttributedString
alloc] initWithString:@
"strigil"
attributes:attrsDictionary];
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:str];
[attributeString setAttributes:@{NSForegroundColorAttributeName: [UIColor redColor], NSFontAttributeName:[UIFont systemFontOfSize:17]} range:NSMakeRange(2, 1)];NSRange range =[str rangeOfString:keyword];
[attributeString setAttributes:@{NSForegroundColorAttributeName: [UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:17]} range:range];
// 绘制图片
UIImage *image = [UIImage imageNamed:@"darkLight.png"];
[image drawAtPoint:CGPointMake(120, 300)];
// 绘制文字
NSString *str = @"ABCDEF";
UIFont *font = [UIFont systemFontOfSize:12];
NSDictionary *dictory = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
//NSAttributedString *str1 = [[NSAttributedString alloc]initWithString:str attributes:dictory];
// 通过画图的方式自动调用绘图功能
[str drawInRect:CGRectMake(100, 100, 200, 50) withAttributes:dictory];
// 绘制直线
// 获取绘图的上下文
CGContextRef ref = UIGraphicsGetCurrentContext();
// 设置绘图的画笔的大小
CGContextSetLineWidth(ref, 1.0);
// 设置绘图的边线样式
CGContextSetLineCap(ref, kCGLineCapRound);
// 20个像素的虚线有10个空格
//float lenghts [] = {20, 10};
// 设置虚线
//CGContextSetLineDash(ref, 0, lenghts, 2);
// 设置线条的颜色
CGContextSetStrokeColorWithColor(ref, [UIColor blackColor].CGColor);
// 移动绘图点
CGContextMoveToPoint(ref, 100, 100);
// 绘制直线
CGContextAddLineToPoint(ref, 220, 220);
CGContextAddLineToPoint(ref, 100, 220);
// 封闭曲线(这样只需填写3个点即可)
CGContextClosePath(ref);
// 开始绘制线并在view上显示(最终调用的方法)
CGContextStrokePath(ref);
// 绘制图
CGContextSetFillColorWithColor(ref, [UIColor greenColor].CGColor);
// 线条颜色
CGContextSetStrokeColorWithColor(ref, [UIColor blackColor].CGColor);
// 设置透明度
CGContextSetAlpha(ref, 0.5);
// 设置影子偏移量
CGContextSetShadowWithColor(ref, CGSizeMake(20, 20), 20, [UIColor orangeColor].CGColor);
// 设置图形样式
CGContextAddRect(ref, CGRectMake(100, 100, 100, 100));
//图形显示方式为:线条填充图一起显示(此方法一定要在绘制图形完成后使用,否则无效)
CGContextDrawPath(ref, kCGPathFillStroke);
CGContextStrokePath(ref);
//绘制圆填充颜色
CGContextSetFillColorWithColor(ref, [UIColor redColor].CGColor);
//如果没有这句,那么下面绘制就是一个从0度到100度的圆型的一部分,因为没有设置move点
CGContextMoveToPoint(ref, 150, 150);
//(100为半径,最后的0说明时顺时针[逆时针为1])
CGContextAddArc(ref, 150, 150, 100, 0 * M_PI / 180, 100 * M_PI / 180, 0);
CGContextFillPath(ref);
CGContextSetFillColorWithColor(ref, [UIColor blackColor].CGColor);
CGContextMoveToPoint(ref, 150, 150);
// 150 150是坐标 100是半径 M_PI是180度
CGContextAddArc(ref, 150, 150, 100, 100 * M_PI / 180, 230 * M_PI / 180, 0);
CGContextFillPath(ref);
CGContextSetFillColorWithColor(ref, [UIColor blueColor].CGColor);
CGContextMoveToPoint(ref, 150, 150);
CGContextAddArc(ref, 150, 150, 100, 230 * M_PI / 180, 360 * M_PI / 180, 0);
CGContextFillPath(ref);
// 绘制曲线(100, 350是开始点)
CGContextMoveToPoint(ref, 100, 350);
//(120,250)是弧线顶点的坐标 (300,350)是弧线最右端的坐标(220, 250是弯曲的曲线上的一个点)
CGContextAddQuadCurveToPoint(ref, 220, 250, 300, 350);
CGContextStrokePath(ref);