美文网首页
iOS - coreText简单使用

iOS - coreText简单使用

作者: lizhi_boy | 来源:发表于2019-03-21 16:45 被阅读0次
- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    
    //获取上下文
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    //坐标转换
    CGContextSetTextMatrix(context, CGAffineTransformIdentity);
    CGContextTranslateCTM(context, 0, self.bounds.size.height);
    CGContextScaleCTM(context, 1.0, -1);
    
    
    //绘制区域
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddEllipseInRect(path, NULL, self.bounds);
    
    
    //添加内容
    NSAttributedString *attstring = [[NSAttributedString alloc] initWithString:@"富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我是富文本哦哦我"];
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attstring);
    CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attstring length]), path, NULL);
    //绘制
    CTFrameDraw(frame, context);
    
    
    CFRelease(frame);
    CFRelease(path);
    CFRelease(framesetter);
    
    
}

相关文章

网友评论

      本文标题:iOS - coreText简单使用

      本文链接:https://www.haomeiwen.com/subject/bsufvqtx.html