1

I was using a library (SGInfoAlert) which uses deprecated code drawInRect:r withFont:. I tried changing some codes to fix it in iOS 7 but the text doesn't show. Anyone knows why this is happening?

// Changed this
//[info_ drawInRect:r withFont:[UIFont systemFontOfSize:kSGInfoAlert_fontSize]];

// To this
NSDictionary *textAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:kSGInfoAlert_fontSize]};

[info_ drawInRect:r withAttributes:textAttributes];

Here is the git repository https://github.com/sagiwei/SGInfoAlert

Sonny G
  • 1,331
  • 1
  • 12
  • 22

1 Answers1

8

Ok. I found a fix.

// iOS 7 fix
UIFont* font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];

NSDictionary *attrs = @{ NSForegroundColorAttributeName : [UIColor whiteColor],
                         NSFontAttributeName : font,
                         NSTextEffectAttributeName : NSTextEffectLetterpressStyle};


[info_ drawInRect:r withAttributes:attrs];
Sonny G
  • 1,331
  • 1
  • 12
  • 22
  • Anyone know why "NSTextEffectAttributeName" parameter is required here? I get a crash in my code if I don't set this, although it works fine if I do, but the only possible value is NSTextEffectLetterpressStyle, which I don't really want. – Peter Johnson Dec 16 '14 at 13:11
  • @PeterJohnson in my case it works without this attribute, so, probably, it's not required. – Yaroslav Havrylovych Dec 14 '18 at 10:06