幾乎是在入行的時(shí)候就已經(jīng)開(kāi)始接觸UIFont這個(gè)類(lèi),但是從來(lái)沒(méi)有細(xì)細(xì)去研究過(guò)它里邊到底都有什么,最近工作中遇到了相關(guān)問(wèn)題就順道細(xì)細(xì)研究了一下委乌。
單純的使用這個(gè)類(lèi)很簡(jiǎn)單,我主要說(shuō)的是其中的屬性荣回。
@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 ;
@property(nonatomic,readonly) CGFloat leading;
- familyName 字體家族的名字
- fontName 字體的名字
- pointSize 字體大小
- ascender 基準(zhǔn)線(xiàn)以上的高度
- descender 基準(zhǔn)線(xiàn)以下的高度
- capHeight 大小的高度
- xHeight 小寫(xiě)x的高度
- lineHeight 當(dāng)前字體下的行高
- leading 行間距(一般為0)
具體代碼運(yùn)行結(jié)果可以更加清楚的說(shuō)明各個(gè)屬性的值遭贸,代碼以14號(hào)字體為例
UIFont *font = [UIFont systemFontOfSize:14];
NSLog(@"font.pointSize = %f,font.ascender = %f,font.descender = %f,font.capHeight = %f,font.xHeight = %f,font.lineHeight = %f,font.leading = %f",font.pointSize,font.ascender,font.descender,font.capHeight,font.xHeight,font.lineHeight,font.leading);
運(yùn)行結(jié)果如下
font.pointSize = 14.000000,font.ascender = 13.330078,font.descender = -3.376953,font.capHeight = 9.864258,font.xHeight = 7.369141,font.lineHeight = 16.707031,font.leading = 0.000000
其中可以很明顯的看到:
- 設(shè)置的字體大小就是 pointSize
- ascender + descender = lineHeight
3.實(shí)際行與行之間就是存在間隙的,間隙大小即為 lineHeight - pointSize驹马,在富文本中設(shè)置行高的時(shí)候革砸,其實(shí)際文字間的距離就是加上這個(gè)距離的除秀。(原來(lái)一直錯(cuò)誤的理解文字間的距離就是行間距)