目前在学coreText绘制,为什么绘制的区域的背景色是黑色,怎么设置背景色?

来源:互联网 发布:云计算 搭建 openstack 编辑:程序博客网 时间:2024/04/30 05:50
目前在学coreText绘制,为什么绘制的区域的背景色是黑色 ?
尝试很多方法都没法改变绘制区的背景色,求指点。

#import "TXTCView.h"

@implementation TXTCView



- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    self.backgroundColor = [UIColor whiteColor];
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGMutablePathRef path = CGPathCreateMutable();//1
    CGPathAddRect(path, NULL, self.bounds);
    
    NSAttributedString * attString = [[NSAttributedString alloc] initWithString:@"Hello core text World!!"];
    
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attString);
    CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attString length]), path, NULL);
    CTFrameDraw(frame, context);//4
    
    CFRelease(frame);//5
    CFRelease(path);
    CFRelease(framesetter);
}

0 0
原创粉丝点击