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
}
}
网友评论