将文本写入CGContext时发生奇怪错误

时间:2014-10-17 17:29:54

标签: ios quartz-graphics cgcontext

我正在尝试使用此代码将文本写入CGContext

  NSString *text = NSLocalizedString(@"myText", nil);

  NSDictionary *atributes = @{
                                    NSFontAttributeName : @"Helvetica Neue Bold",
                                    NSForegroundColorAttributeName : [UIColor blackColor]
                                    };

  [text drawAtPoint:CGPointMake(x1, y2) withAttributes: attributes];

但我看到了这个错误

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSCFConstantString pointSize]:无法识别的选择器发送到实例0x1001dfd40

任何线索?

1 个答案:

答案 0 :(得分:2)

UIFont设置NSFontAttributeName个对象。

NSString *text = NSLocalizedString(@"myText", nil);

NSDictionary *atributes = @{
                            NSFontAttributeName : [UIFont fontWithName:@"Helvetica Neue Bold" size: 17.0],
                            NSForegroundColorAttributeName : [UIColor blackColor]
                            };

[text drawAtPoint:CGPointMake(x1, y2) withAttributes: attributes];