【问题标题】:CoreText Framesetter with Quartz 2d - Text is Drawing from Bottom to Top - iOSCoreText Framesetter with Quartz 2d - 文本从下到上绘制 - iOS
【发布时间】: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


    【解决方案1】:

    在 Quartz 2D 中有不同的坐标系。你必须翻转上下文,你可以使用:

    CGContextTranslateCTM(currentContext, 0, 100);
    CGContextScaleCTM(currentContext, 1.0, -1.0);
    

    它对我有用。

    【讨论】:

    • 我不在基于 UIView 的类中 - self.bounds.size.height 是什么?还有这段代码去哪里了?
    • 那你是什么子类?
    • 非常感谢。
    猜你喜欢
    • 2012-10-05
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    相关资源
    最近更新 更多