Skip to content

Instantly share code, notes, and snippets.

@yxztj
Created June 4, 2018 02:30
Show Gist options
  • Save yxztj/c1ead7358879e902c5c01b8d6186c1f2 to your computer and use it in GitHub Desktop.
Save yxztj/c1ead7358879e902c5c01b8d6186c1f2 to your computer and use it in GitHub Desktop.
Wrong size for Chinese text
import UIKit
import PlaygroundSupport
let paragraph = NSMutableParagraphStyle()
paragraph.lineSpacing = 20
// the issue won't report with PingFangSC-Regular font
//let font = UIFont(name: "PingFangSC-Regular", size: 18)!
// setting to ".SFUIText" would lead to reproductive
let font = UIFont(name: ".SFUIText", size: 18)!
// And also this issue only repro for CJK language
let text = "你好"
// setting to english is good
//let text = "hello"
let attrText = NSAttributedString(string: text, attributes: [NSAttributedStringKey.paragraphStyle: paragraph, NSAttributedStringKey.font: font])
let label = UILabel()
label.attributedText = attrText
label.sizeToFit()
label.backgroundColor = UIColor.white
PlaygroundPage.current.liveView = label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment