【发布时间】:2013-12-06 11:47:28
【问题描述】:
我正在使用以下代码来绘制 Core Text 文本框架,然后将其添加到 Quartz 2D 绘制形状。问题是文本是从下到上绘制的,而不是从上到下(见截图)。有人可以帮忙吗?
- (void)drawText:(CGContextRef)contextP startX:(float)x startY:(float)
y withText:(NSString *)standString
{
CGContextSetTextMatrix(contextP, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
CGRect frameText = CGRectMake(0, 0, (right-left)*2, (bottom-top)*2);
NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:@"This is a test string to test the string"];
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(attrString));
struct CGPath * p = CGPathCreateMutable();
CGPathAddRect(p, NULL, frameText);
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0,0), p, NULL);
CTFrameDraw(frame, contextP);
}
【问题讨论】:
标签: ios objective-c text quartz-2d core-text