基于CoreText的基础排版引擎之不带图片的排版引擎
2015-07-12 21:33
507 查看
- (void)drawRect:(CGRect)rect { [super drawRect:rect]; //步骤一:得到当前绘制画布上下文,用于后续将内容绘制在画布上 CGContextRef context = UIGraphicsGetCurrentContext(); //步骤二:将坐标系上下翻转。对于底层的绘制引擎来说,屏幕左下角是(0,0)坐标。而对于上层的UIKit来说,左上角是(0,0)坐标。所以我们为了之后的坐标系描述按UIKit来显示,这里做了一个坐标系上下翻转操作。翻转之后,底层和上层的(0,0)坐标就是重合的了。 CGContextSetTextMatrix(context, CGAffineTransformIdentity); CGContextTranslateCTM(context, 0, self.bounds.size.height); CGContextScaleCTM(context, 1.0, -1.0); //步骤三:创建绘制区域 CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, NULL, self.bounds); // CGPathAddEllipseInRect(path, NULL, self.bounds); //步骤四 NSAttributedString *attString = [[NSAttributedString alloc] initWithString:@"ScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhangScottZhang"]; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attString); CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attString length]), path, NULL); //步骤五 CTFrameDraw(frame, context); //步骤六 CFRelease(frame); CFRelease(path); CFRelease(framesetter); }
相关文章推荐
- Java反射机制
- C#方法参数传递机制
- 哈夫曼编码算法思想总结
- bzoj1146: [CTSC2008]网络管理Network 树套树
- SOCKET编程
- 临时数据的存储
- c# ListBox绑定对象时删除数据的问题
- win7下python执行cmd命令中exe崩溃的处理
- Netty系列之Netty百万级推送服务设计要点
- linux块设备驱动之请求过程剖析
- 算法二之子集和数问题
- Cocos2d-x发展---更改父的颜色、透明度的子节点上
- STM32 Printf函数实现方法 (转载)
- ulimit关于系统连接数的优化
- 喵哈哈村的挑衅(区间DP)
- linux shenll 远程执行本地脚本或者执行命令
- maven 忽略checkstyle
- PAT 数据结构 04-树9. Path in a Heap (25)
- 【spring学习前奏】JavaBean内省Introspector以及BeanInfo
- 您是微信“环”么