需求: ? ? ??
? ? ? ?最近項(xiàng)目需要添加新字體如下圖中 "我的當(dāng)前積分:500" 字體要求FZHCJW--GB1-0,在網(wǎng)上查知曉是方正黃草簡體,這個(gè)查了系統(tǒng)familyNames中沒有,這該怎么實(shí)現(xiàn)呢?
分析:
? ? ? ? 我們需要添加相應(yīng)的字體到系統(tǒng)的familyNames中,在網(wǎng)上搜索發(fā)現(xiàn)外嵌字體都是.ttf格式的,那我們就需要下載相應(yīng)的字體文件,引入工程進(jìn)而去使用這種字體。
實(shí)現(xiàn):
首先,我在小新圖庫下載相應(yīng)的字體的.ttf文件導(dǎo)入了工程,
確認(rèn)工程copy進(jìn)來了我這里導(dǎo)入的是: 方正草黃簡體.ttf
在info.plist中加入這個(gè)
接下來,我們輸出一下系統(tǒng)字體
NSLog(@"Font %@",[UIFont familyNames]);
會(huì)發(fā)現(xiàn)多出來FZHuangCao-S09S,有了這個(gè)我們就可以設(shè)置新字體了,代碼如下:
intergralLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, SCREENH(315.0f/2.0f)/2.0f, kScreen_W, 18.0f)];
UIFontDescriptor *attributeFontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:@{UIFontDescriptorNameAttribute:@"FZHuangCao-S09S",UIFontDescriptorSizeAttribute: @15.0}];
intergralLabel.font = [UIFont fontWithDescriptor:attributeFontDescriptor size:0.0];