Skip to content

Instantly share code, notes, and snippets.

@takehito-koshimizu
Last active August 29, 2015 14:17
Show Gist options
  • Save takehito-koshimizu/05bd614f980ce7c7d7d2 to your computer and use it in GitHub Desktop.
Save takehito-koshimizu/05bd614f980ce7c7d7d2 to your computer and use it in GitHub Desktop.
ヒラギノフォントで日本語に英語を混ぜると正しく表示できなるCoreTextのバグ対策のためのカスタムUILabel
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