为有牺牲多壮志,敢教日月换新天。

[Xcode 实际操作]九、实用进阶-(2)遍历设备(输出系统)上的所有字体

热烈欢迎,请直接点击!!!

进入博主App Store主页,下载使用各个作品!!!

注:博主将坚持每月上线一个新app!!!

目录:[Swift]Xcode实际操作

在实际工作中,经常需要调整界面元素的字体种类。

本文将演示输出系统提供的所有字体,方便检索和使用。

在项目导航区,打开视图控制器的代码文件【ViewController.swift】

 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 }

 

posted @ 2018-12-07 20:24  为敢技术  阅读(120)  评论(0编辑  收藏  举报