1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| let label = UILabel() label.text = "这是啥"
let format: (UIFont) -> [String: Any] = { (font) in label.font = font label.sizeToFit() return ["font.familyName": font.familyName, "font.fontName": font.fontName, "font.pointSize": font.pointSize, "font.ascender": font.ascender, "font.descender": font.descender, "font.capHeight": font.capHeight, "font.xHeight": font.xHeight, "font.lineHeight": font.lineHeight, "font.leading": font.leading, "label.sizeToFit": label.frame.height] }
var json: [String: [[String: Any]]] = [:] for family in UIFont.familyNames { for name in UIFont.fontNames(forFamilyName: family) { var list: [[String: Any]] = [] for size in 5...60 { guard let font = UIFont.init(name: name, size: CGFloat(size)) else { continue } list.append(format(font)) } json["\(family) -> \(name)"] = list } } print(String(data:(try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)) ?? Data(), encoding: .utf8)!)
|