Ios7 drawInRect:withFont:iOS 7不工作

Ios7 drawInRect:withFont:iOS 7不工作,ios7,deprecated,drawinrect,Ios7,Deprecated,Drawinrect,我使用的是一个库(SGInfoAlert),它使用了不推荐使用的代码drawInRect:r和字体:。 我试着在iOS 7中修改一些代码来修复它,但是文本没有显示出来。有人知道为什么会这样吗 // Changed this //[info_ drawInRect:r withFont:[UIFont systemFontOfSize:kSGInfoAlert_fontSize]]; // To this NSDictionary *textAttributes = @{NSFontAttrib

我使用的是一个库(SGInfoAlert),它使用了不推荐使用的代码drawInRect:r和字体:。 我试着在iOS 7中修改一些代码来修复它,但是文本没有显示出来。有人知道为什么会这样吗

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

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

[info_ drawInRect:r withAttributes:textAttributes];
这是git存储库

Ok。我找到了解决办法

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

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


[info_ drawInRect:r withAttributes:attrs];
嗯。我找到了解决办法

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

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


[info_ drawInRect:r withAttributes:attrs];

有人知道为什么这里需要“NSTextEffectAttributeName”参数吗?如果我不设置此属性,我的代码会崩溃,尽管设置后效果很好,但唯一可能的值是NSTEXTEFFECTRETTERPRESSTYLE,这不是我真正想要的。@PeterJohnson在我的例子中,它在没有此属性的情况下工作,所以,可能不是必需的。有人知道为什么这里需要“NSTEXTEFFECTRETTERATTRIBUTENAME”参数吗?如果不设置此属性,我的代码会崩溃,尽管设置后效果很好,但唯一可能的值是NSTEXTEFFECTLETTPRESSTYLE,我并不真正想要它。@在我的例子中,它在没有此属性的情况下工作,因此,可能不需要它。