蘋果在細(xì)節(jié)方面,雖然下了很大的功夫,但是仍然會(huì)有些需求是無(wú)法涵蓋到的,比如之前在項(xiàng)目中遇到的特殊字體的設(shè)置。字體都會(huì)有相應(yīng)的字體文件,一般是以ttf或otf為后綴。我們就以百度綜藝簡(jiǎn)體(bdzy.ttf)為例。
首先,需要下載ttf字體文件,下載之后將字體copy到資源文件,

加入字體后,在info.plist文件中設(shè)置相應(yīng)字體設(shè)置信息。

接下來,我們通過代碼來獲取字體對(duì)應(yīng)的字庫(kù)名稱。
for(NSString*fontFamilyNamein[UIFontfamilyNames]) {
NSLog(@"--- %@ ---", fontFamilyName);
for(NSString*fontNamein[UIFontfontNamesForFamilyName:fontFamilyName]) {
NSLog(@"%@", fontName);
}
NSLog(@"");
}

到此為止,我們就可以使用ttf文件來設(shè)置想要的字體了。
UILabel*wLabel = [CustomMethodcreateALabelWithframe:CGRectMake(SCREEN_WIDTH/2-100,74,200,50)andWithName:@"百度綜藝簡(jiǎn)體"andTextAlcent:NSTextAlignmentCenterandTextColor:White_ColorandFont:[UIFontsystemFontOfSize:35]];
NSMutableAttributedString*str = [[NSMutableAttributedStringalloc]initWithString:weimeiLabel.text];
NSMutableDictionary*textAttr = [NSMutableDictionarydictionary];
textAttr[NSForegroundColorAttributeName] = [UIColorwhiteColor];
textAttr[NSFontAttributeName] = [UIFontfontWithName:@"BDZYJT--GB1-0"size:35];
[straddAttributes:textAttrrange:NSMakeRange(0,2)];
wLabel.attributedText= str;
[self.viewaddSubview:wLabel];