1
我使用核心文本来显示一些来自Web的json文本。 内容从被弹出的nsdictionary拉到UITABLEVIEW。ctframe不更新ctlines
我的问题是,ctframe不想更新最新的内容,它不断重绘旧文本。我调试它,我很确定ctframesettercreateframe正在使用最新的NSAttributeString
这里是我的代码, 我在每一点调用此函数来显示一个新的文本。该标记解析器会返回一个NSAtributeString
- (void)assign_text:(NSString*)text{
self.text = text;
CGMutablePathRef path = CGPathCreateMutable(); //1
CGPathAddRect(path, NULL, self.bounds);
MarkupParser *markup = [[MarkupParser alloc]init];
NSAttributedString* attString = [markup attrStringFromMarkup: self.text];
CFAttributedStringRef a = (__bridge_retained CFAttributedStringRef)attString;
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(a); //3
ctFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attString length]), path, NULL);
CFRelease(a);
CFRelease(path);
CFRelease(framesetter);
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
// Flip the coordinate system
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, 0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CTFrameDraw((CTFrameRef)ctFrame, context);
}
哇。非常感谢。该视图编程指南绝对是我从未想过要读的东西。 – user1563874 2012-07-30 20:01:17