Created
October 2, 2014 08:24
-
-
Save akisute/672b88181595874f9e7c to your computer and use it in GitHub Desktop.
You will no longer be suffered by iOS 6 Hiragino fonts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)text6Compatible | |
{ | |
return self.text; | |
} | |
- (void)setText6Compatible:(NSString *)text6Compatible | |
{ | |
self.text = text6Compatible; | |
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(7)) { | |
return; | |
} | |
// フォントがヒラギノだった場合のみ盛大にぶっ壊れるので、ヒラギノかどうかで判定する | |
// ヒラギノ (Hiragino Kaku Gothic, Hiragino Mincho) の時だけ補正をかける | |
if ([self.font.familyName hasPrefix:@"Hiragino"] && self.text.length > 0) { | |
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString:self.attributedText]; | |
NSMutableParagraphStyle *style = [[attributedString attribute:NSParagraphStyleAttributeName atIndex:0 effectiveRange:NULL] mutableCopy]; | |
style.maximumLineHeight = self.font.pointSize; | |
style.minimumLineHeight = self.font.pointSize; | |
[attributedString setAttributes:@{NSParagraphStyleAttributeName: style} range:NSMakeRange(0, attributedString.length)]; | |
self.attributedText = attributedString; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment