Last active
August 29, 2015 14:17
-
-
Save takehito-koshimizu/05bd614f980ce7c7d7d2 to your computer and use it in GitHub Desktop.
ヒラギノフォントで日本語に英語を混ぜると正しく表示できなるCoreTextのバグ対策のためのカスタムUILabel
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
import UIKit | |
import CoreText | |
/** | |
ヒラギノフォントで日本語に英語を混ぜると正しく表示できなるCoreTextのバグ対策のためのラベル | |
*/ | |
class HirakakuLabel: UILabel { | |
private var ctFont: CTFont! { | |
return CTFontCreateWithName((font.fontName) as CFStringRef, font.pointSize, nil) | |
} | |
// 「g」、「j」のフォントディセント分、縦に大きくして返します | |
override func intrinsicContentSize() -> CGSize { | |
let superReturnSize: CGSize = super.intrinsicContentSize() | |
return CGSizeMake( | |
superReturnSize.width, | |
superReturnSize.height + 2 * CGFloat(ceilf(Float(CTFontGetDescent(ctFont)))) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment