Duck
Duck

Reputation: 35933

Strange error writing text to CGContext

I am trying to write a text to a CGContext using this code

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

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

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

but I am seeing this error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString pointSize]: unrecognized selector sent to instance 0x1001dfd40

any clues?

Upvotes: 0

Views: 124

Answers (1)

rintaro
rintaro

Reputation: 51911

set UIFont object for 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];

Upvotes: 2

Related Questions