UITableViewを活用したFontListアプリの作成
コード例
FontListViewCotroller.swift
//
// FontListViewController.swift
// FontList
//
import UIKit
class FontListViewController:UITableViewController{
var fontName_array:[String] = []
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return fontName_array.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let fontname = fontName_array[indexPath.row]
cell.textLabel?.font = UIFont(name: fontname, size:20)
cell.textLabel?.text = fontname
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
for fontFamilyName in UIFont.familyNames{
for fontName in UIFont.fontNames(forFamilyName:fontFamilyName){
fontName_array.append(fontName)
}
}
}
}