iOS每日一记————————CoreText初识

额 最近在看唐巧大大的《 iOS开发进阶》这本书 看到了CoreText这个地方 觉得不错 就保存了下来

富文本啊。。。需要用到Coretext这玩意。。。唉

不多说上一个简单的代码好了。。。


-(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.0);
    
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path, NULL, self.bounds);
    
    NSAttributedString *attString = [[NSAttributedString alloc]initWithString:@"Hello World"];
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attString);
    CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attString length]), path, NULL);
    
    CTFrameDraw(frame, conText);
    
    CFRelease(frame);
    CFRelease(path);
    CFRelease(framesetter);
    
}

简单的实现一个Hello World的效果。。。额。。。后期还会继续添加 先就这吧、。。。

你可能感兴趣的:(ios,ios开发,CoreText)