简体   繁体   English

drawInRect:withFont:iOS 7无法正常工作

[英]drawInRect: withFont: iOS 7 not working

I was using a library (SGInfoAlert) which uses deprecated code drawInRect:r withFont:. 我正在使用一个库(SGInfoAlert),该库使用已过时的代码drawInRect:r和Font:。 I tried changing some codes to fix it in iOS 7 but the text doesn't show. 我尝试更改一些代码以在iOS 7中修复它,但文本未显示。 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 这是git存储库https://github.com/sagiwei/SGInfoAlert

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用drawInRect:withAttributes:而不是drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment:在iOS 7中 - How to use drawInRect:withAttributes: instead of drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment: in iOS 7 drawInRect:withFont:lineBreakMode:alignment:'不推荐使用:警告 - drawInRect:withFont:lineBreakMode:alignment:' is deprecated: warning UITableViewCell drawInRect iOS7 - UITableViewCell drawInRect iOS7 使用CoreGraphics的iOS 7 NSString drawInRect - ios 7 NSString drawInRect using CoreGraphics iOS7 弃用 NSString 的 drawAtPoint:forWidth:withFont:minFontSize:actualFontSize:lineBreakMode:baselineAdjustment: - iOS7's deprecation of NSString's drawAtPoint:forWidth:withFont:minFontSize:actualFontSize:lineBreakMode:baselineAdjustment: 试图将我的项目更新为ios 7错误-drawInRect - trying to update my project to ios 7 error - drawInRect deprected NSString drawInRect:withAttributes:绘制的文本宽度不大于iOS 7.0.3中的rect - NSString drawInRect:withAttributes: is not drawing text with greater width than the rect in iOS 7.0.3 使用drawInRect:withAttributes对齐文本: - align text using drawInRect:withAttributes: 在iOS 7上无法在iOS 6上使用writeToFile - writeToFile working on iOS 7 not on iOS 6 CAGradientLayer无法在iOS 7上运行(但在iOS 6上运行) - CAGradientLayer is not working on iOS 7 (But working on iOS 6)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM