Skip to content

Instantly share code, notes, and snippets.

@akisute
Created October 2, 2014 08:24
Show Gist options
  • Save akisute/672b88181595874f9e7c to your computer and use it in GitHub Desktop.
Save akisute/672b88181595874f9e7c to your computer and use it in GitHub Desktop.
You will no longer be suffered by iOS 6 Hiragino fonts.
- (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