首先我們來看一看UIFont的API里面有哪些屬性:
- // Font attributes
- @property(nonatomic,readonly,strong) NSString *familyName;
- @property(nonatomic,readonly,strong) NSString *fontName;
- @property(nonatomic,readonly) CGFloat pointSize;
- @property(nonatomic,readonly) CGFloat ascender;
- @property(nonatomic,readonly) CGFloat descender;
- @property(nonatomic,readonly) CGFloat capHeight;
- @property(nonatomic,readonly) CGFloat xHeight;
- @property(nonatomic,readonly) CGFloat lineHeight NS_AVAILABLE_IOS(4_0);
- @property(nonatomic,readonly) CGFloat leading;
你會發現有這么一大堆屬性然而並不知道都是干嘛的,不用着急,給你們看一張圖就知道了:
現在應該大致知道各個屬性都是干嘛了的吧。
pointSize就是字體的大小,要獲取字體大小就用這個屬性。
而lineHeight是行高,當你要計算這些字所占用的高度的時候,要用這個屬性。
有一個屬性baseLine,指的就是緊貼着這些字符的那條線。
leading指的是如果有多行的話,兩個baseline之間的距離,如果只有一行,那么這個值就是0.
ascender和descender意義很明確,就不說了。
capHeight表示最高的字符的高度。
xHeight表示最低的字符的高度。
fontName表示的字體的名字,familyName會把字體名字分成幾部分,用空格隔開。