2014-02-13 44 views
1

我正在使用一個庫(SGInfoAlert),它使用了不推薦的代碼drawInRect:r withFont :. 我試着改變一些代碼來修復它在iOS 7中,但文本不顯示。任何人都知道這是爲什麼發生?drawInRect: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

回答

5

確定。我找到了一個修復。

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

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


[info_ drawInRect:r withAttributes:attrs]; 
+0

任何人都知道爲什麼在這裏需要「NSTextEffectAttributeName」參數? 如果我沒有設置這個,我會在代碼中崩潰,但是如果我這樣做的話它可以正常工作,但唯一可能的值是NSTextEffectLetterpressStyle,我並不想要它。 –