LoginSignup
2
1

More than 5 years have passed since last update.

[iOS]UITableViewを活用したFontListアプリの作成

Last updated at Posted at 2017-10-24

UITableViewを活用したFontListアプリの作成

スクリーンショット 2017-10-24 15.39.59.png

コード例

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)
            }
        }
    }
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1