【问题标题】:drawInRect: withFont: iOS 7 not workingdrawInRect:withFont:iOS 7 不工作
【发布时间】:2014-03-11 22:37:18
【问题描述】:

我正在使用一个库 (SGInfoAlert),它使用已弃用的代码 drawInRect:r withFont:。 我尝试更改一些代码以在 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 仓库https://github.com/sagiwei/SGInfoAlert

【问题讨论】:

    标签: ios7 deprecated drawinrect


    【解决方案1】:

    好的。我找到了解决办法。

    // iOS 7 fix
    UIFont* font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
    
    NSDictionary *attrs = @{ NSForegroundColorAttributeName : [UIColor whiteColor],
                             NSFontAttributeName : font,
                             NSTextEffectAttributeName : NSTextEffectLetterpressStyle};
    
    
    [info_ drawInRect:r withAttributes:attrs];
    

    【讨论】:

    • 有人知道为什么这里需要“NSTextEffectAttributeName”参数吗?如果我不设置它,我的代码会崩溃,虽然如果我这样做它工作正常,但唯一可能的值是 NSTextEffectLetterpressStyle,我真的不想要。
    • @PeterJohnson 在我的情况下它可以在没有此属性的情况下工作,因此可能不需要它。
    猜你喜欢
    • 2023-03-10
    • 2020-10-04
    • 2011-05-24
    • 2014-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多