[Swift通天遁地]8、媒體與動畫-(12)CoreText框架中的字體的FontMetrics佈局信息

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-nerovduu-mc.html 
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html

目錄:[Swift]通天遁地Swiftgit

本文將演示字體的佈局信息。文字的佈局就是將衆多字形,經過必定的規則排列在顯示設備上。github

文字分佈的區域被稱爲文本區,字形的排列是基於一條不可見的線進行排列的,這條抽象的線稱爲基線。swift

在左側的項目導航區,打開視圖控制器的代碼文件【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         let font = UIFont.systemFont(ofSize: 24)
11         
12         //輸出字體對象的上行高度,即基線與字形最高點之間的距離。
13         print("font.ascender: \(font.ascender)")
14         //輸出字體對象的下行高度,即基線與字形最低點之間的距離。
15         print("font.descender: \(font.descender)")
16         //輸出基線到大寫字母最高點的距離。
17         print("font.capHeight: \(font.capHeight)")
18         //輸出基線至非突出的小寫字母最高點的距離。
19         print("font.xHeight: \(font.xHeight)")
20         //輸出一行字形的最大高度,等於前三個屬性值的和。
21         print("font.lineHeight: \(font.lineHeight)")
22         //輸出行距的數值,即上方一行的最低點,與下方一行的最高點的距離
23         print("font.leading: \(font.leading)")
24     }
25 
26     override func didReceiveMemoryWarning() {
27         super.didReceiveMemoryWarning()
28         // Dispose of any resources that can be recreated.
29     }
30 }
相關文章
相關標籤/搜索