美文网首页
Swift - iOS中所有内置的字体

Swift - iOS中所有内置的字体

作者: Hesse_Huang | 来源:发表于2016-09-07 14:24 被阅读167次
class TableViewController: UITableViewController {
    
    // 所有字体,这是一个(String, [String])元组的数组
    let fonts: [(String, [String])] = UIFont.familyNames().map({ ($0, UIFont.fontNamesForFamilyName($0)) })

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return fonts.count
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return fonts[section].1.count
    }

    override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return fonts[section].0
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("font", forIndexPath: indexPath)
        let fontName = fonts[indexPath.section].1[indexPath.row]
        cell.textLabel?.text = fontName
        cell.textLabel?.font = UIFont(name: fontName, size: 17)
        return cell
    }

}

相关文章

网友评论

      本文标题:Swift - iOS中所有内置的字体

      本文链接:https://www.haomeiwen.com/subject/fzpjettx.html