博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于CoreText的基础排版引擎之不带图片的排版引擎
阅读量:7226 次
发布时间:2019-06-29

本文共 1425 字,大约阅读时间需要 4 分钟。

- (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);}

转载地址:http://hieym.baihongyu.com/

你可能感兴趣的文章
P4492 [HAOI2018]苹果树
查看>>
U3D Invoke() IsInvoking CancelInvoke方法的调用
查看>>
pyalgotrade入门
查看>>
2018你应该了解这些.NET面试题
查看>>
putty
查看>>
PHP中define和defined的区别
查看>>
AtCoder Regular Contest 089
查看>>
真正掌握vuex的使用方法(三)
查看>>
[HDU5751]Eades
查看>>
Django 分页组件替换自定义分页
查看>>
移动端 图片大小方式
查看>>
第0次作业
查看>>
HTML5游戏 看你有多“色” 开发
查看>>
Intel-面试经历
查看>>
Pdf Convert Image 的解决方案
查看>>
变形与动画
查看>>
根据第三方库spire.pdf使用指定打印机打印pdf文件
查看>>
mysql之存储过程
查看>>
使用intelliJ创建 spring boot + gradle + mybatis站点
查看>>
第八章 方法
查看>>