Created
June 4, 2018 02:30
-
-
Save yxztj/c1ead7358879e902c5c01b8d6186c1f2 to your computer and use it in GitHub Desktop.
Wrong size for Chinese text
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 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