码迷,mamicode.com
首页 > 移动开发 > 详细

ios绘制基本图形之水印背景

时间:2016-01-22 16:58:41      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

 1 @interface NJTextImage : UIView
 2 @end
 3 
 4 
 5 @implementation NJTextImage
 6 
 7 - (void)drawRect:(CGRect)rect
 8 {    
 9 //    [self test];
10 //    1.加载图片到内存中
11     UIImage *image = [UIImage imageNamed:@"bg"];
12     
13     // 利用OC方法将图片绘制到layer上
14     // 将图片绘制到指定的位置
15     [image drawAtPoint:CGPointMake(0, 0)];
16     
17     // 利用drawInRect方法绘制图片到layer, 是通过拉伸原有图片
18 //    [image drawInRect:CGRectMake(0, 0, 40, 40)];
19     
20     // 利用drawAsPatternInRec方法绘制图片到layer, 是通过平铺原有图片
21 //    [image drawAsPatternInRect:CGRectMake(0, 0, 320, 480)];
22     
23 }
24 
25 - (void)test
26 {
27     // 画文字
28     NSString *str = @"天气好热地方和计算机的开了房间了开始的解放路口时间疯狂的老师;快疯了;SD卡;焚枯食淡;李开复;顺丰快递说了;开发;拉伸放假快乐的设计风格看了就打算离开房间的数量会计分录开始觉得";
29     
30     // 1.获取上下文
31     //    CGContextRef ctx = UIGraphicsGetCurrentContext();
32     // 2.绘图
33     // 不推荐使用C语言的方法绘制文字, 因为quraz2d中的坐标系和UIkit中的坐标系不一致, 绘制出来的文字是颠倒的, 而且通过C语言的方法绘制文字相当麻烦
34     //    CGContextSelectFont(<#CGContextRef c#>, <#const char *name#>, <#CGFloat size#>, <#CGTextEncoding textEncoding#>)
35     //    CGContextShowText(ctx, <#const char *string#>, <#size_t length#>)
36     
37     // 绘制矩形
38     // 1.获取上下文
39     CGContextRef ctx = UIGraphicsGetCurrentContext();
40     // 2.绘图
41     CGContextAddRect(ctx, CGRectMake(50, 50, 100, 100));
42     // 3.渲染
43     CGContextStrokePath(ctx);
44     
45     NSMutableDictionary *md = [NSMutableDictionary dictionary];
46     // 设置文字颜色
47     md[NSForegroundColorAttributeName] =[UIColor redColor];
48     // 设置文字背景颜色
49     md[NSBackgroundColorAttributeName] = [UIColor greenColor];
50     // 设置文字大小
51     md[NSFontAttributeName] = [UIFont systemFontOfSize:20];
52     
53 //    将文字绘制到指点的位置
54 //    [str drawAtPoint:CGPointMake(10, 10) withAttributes:md];
55     
56 //    将文字绘制到指定的范围内, 如果一行装不下会自动换行, 当文字超出范围后就不显示
57     [str drawInRect:CGRectMake(50, 50, 100, 100) withAttributes:nil];
58     
59     
60 }
61 
62 @end

 

ios绘制基本图形之水印背景

标签:

原文地址:http://www.cnblogs.com/PJHome/p/5151229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!