drawInRect: withFont: iOS 7 not working

2.5k Views Asked by At

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

1

There are 1 best solutions below

2
On

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];