zoukankan      html  css  js  c++  java
  • 基于CoreText的基础排版引擎之不带图片的排版引擎

    - (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);
    
    }
  • 相关阅读:
    linux常用脚本
    shell学习笔记
    Linux常用命令List
    Centos7部署Zabbix
    centos7安装nagios步骤
    nagios报错HTTP WARNING: HTTP/1.1 403 Forbidden解决方法
    U盘安装CentOS7
    Thread线程控制之sleep、join、setDaemon方法的用处
    EfficientDet框架详解 | 目前最高最快最小模型,可扩缩且高效的目标检测(附源码下载)
    ubuntu18.04 安装多版本cuda ,原来版本为9.0,在新增8.0
  • 原文地址:https://www.cnblogs.com/zhanggui/p/4641579.html
Copyright © 2011-2022 走看看