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

iOS 码拜 9年前 (2015-05-01) 1003次浏览 0个评论

目前在学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);
}

目前在学coreText绘制,为什么绘制的区域的背景色是黑色,怎么设置背景色?
UIColor *bgColor = [UIColor whiteColor];
[bgColor set];
目前在学coreText绘制,为什么绘制的区域的背景色是黑色,怎么设置背景色?
我试过还是不行
目前在学coreText绘制,为什么绘制的区域的背景色是黑色,怎么设置背景色?
20分
引用 2 楼 LmyangBK 的回复:

我试过还是不行

那是因为少了一句填充颜色的代码:

CGContextFillPath(context);

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明目前在学coreText绘制,为什么绘制的区域的背景色是黑色,怎么设置背景色?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!