[Xcode 實際操做]9、實用進階-(2)遍歷設備(輸出系統)上的全部字體

目錄:[Swift]Xcode實際操做html

在實際工做中,常常須要調整界面元素的字體種類。swift

本文將演示輸出系統提供的全部字體,方便檢索和使用。ide

在項目導航區,打開視圖控制器的代碼文件【ViewController.swift】post

 1 import UIKit
 2 
 3 class ViewController: UIViewController {
 4 
 5     override func viewDidLoad() {
 6         super.viewDidLoad()
 7         // Do any additional setup after loading the view, typically from a nib.
 8         
 9         //首先對設備中全部的字體進行遍歷操做
10         for familyName in UIFont.familyNames
11         {
12             //在控制檯打印輸出字體組信息
13             print("\n[\(familyName)]")
14             //查找並遍歷,字體組中的全部字體的名稱
15             for font in UIFont.fontNames(forFamilyName: familyName)
16             {
17                 //並在控制檯打印輸出字體的名稱
18                 print("\t\(font)")
19             }
20         }
21     }
22 
23     override func didReceiveMemoryWarning() {
24         super.didReceiveMemoryWarning()
25         // Dispose of any resources that can be recreated.
26     }
27 }
相關文章
相關標籤/搜索