Lev
Lev

Reputation: 760

– drawInRect:withAttributes: crashes when setting UIFont

I have this code:

   UIGraphicsBeginImageContextWithOptions(CGSizeMake(100, 100), NO, 0);
   UIFont* font = [UIFont systemFontOfSize:12.0f];
   NSDictionary* attributes = @{ NSFontAttributeName: font };
   [@"hello" drawInRect:CGRectMake(0, 0, 100, 100) withAttributes:attributes];
   UIGraphicsEndImageContext();

It crashes in drawInRect with

-[__NSDictionaryI font]: unrecognized selector sent to instance 0xcb77be0

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI font]: unrecognized selector sent to instance 0xcb77be0'

It works fine if I use deprecated

[@"hello" drawInRect:CGRectMake(0, 0, 100, 100) withFont:font];

What am I doing wrong?

Upvotes: 0

Views: 533

Answers (1)

LongNV
LongNV

Reputation: 902

The reason is you deployed your app on old iOS versio (<7.0) which didn't support method drawInRect:withAttributes:. Also, that's why you could run the deprecated one without problem.

Upvotes: 1

Related Questions