【问题标题】:CGContext set text to justify right when generating a pdfCGContext在生成pdf时将文本设置为正确对齐
【发布时间】:2011-08-16 10:47:47
【问题描述】:

我正在使用一系列 CGContext 命令来创建用于生成 pdf 文件的文本:

CGContextSelectFont (pdfContext, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
CGContextSetTextMatrix(pdfContext, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));

我想右对齐文本。关于如何做到这一点的任何想法?例如,有没有一种方法可以让您将原点指定为文本的右上角,而不是左上角?

    CGContextShowTextAtPoint (pdfContext, x, y, text, strlen(text));

谢谢!

【问题讨论】:

    标签: iphone objective-c xcode pdf cgcontext


    【解决方案1】:

    不支持右对齐和居中对齐。为了绘制右对齐文本,您需要计算文本宽度,从右对齐 x 中减去文本宽度,然后在计算的位置绘制文本。

    【讨论】:

      猜你喜欢
      • 2018-11-13
      • 1970-01-01
      • 2022-01-03
      • 2015-12-03
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 2018-10-18
      • 2017-04-01
      相关资源
      最近更新 更多