【问题标题】:drawing text using CGContextShowTextAtPoint but text shown is inverted,使用 CGContextShowTextAtPoint 绘制文本,但显示的文本是反转的,
【发布时间】:2012-03-04 06:08:38
【问题描述】:
  - (void)drawRect:(CGRect)rect {
    CGContextRef  context = UIGraphicsGetCurrentContext();


    CGContextSelectFont(context, "Arial", 24, kCGEncodingMacRoman);


    CGContextShowTextAtPoint(context, 80, 80, "I am Rahul", 7);





 }

我正在尝试绘制如上图所示的文本“我是拉胡尔”,但是当我执行代码时,
文字被显示,但它是倒置的,为什么会发生我没有得到!救命!!

【问题讨论】:

标签: iphone


【解决方案1】:

您可以使用此代码:

CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));

【讨论】:

  • user338322 你真的应该把它标记为答案,因为它工作得很好。
  • 只是补充一下 - 之所以可行,是因为 UIKit 的坐标系与 CoreGraphics 不同。
【解决方案2】:

这更容易:

- (void)drawRect:(CGRect)rect {
    NSString* string = @"I am Rahul";
    [string drawAtPoint:CGPointMake(80, 80)
               withFont:[UIFont systemFontOfSize:24]];
}

【讨论】:

  • [string drawAtPoint: withFont:] 已被 Apple 弃用。您现在必须使用 [string drawAtPoint: withAttributes:]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-12
  • 2016-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多