本文介绍了自定义字体不能在Xcode中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的iOS应用程序中使用truetype(.ttf)字体,但它不起作用。我已经添加了字体到我的项目,并正确添加目标。我在应用程序提供的字体下的info.plist中添加了字体。我正在使用一个NSAttributedString来显示文本,这是我的代码



$ $ p $ UFont * hrFont = [UIFont fontWithName:@ocrbsize :18.0];
NSDictionary * hrDict = [NSDictionary dictionaryWithObject:hrFont forKey:NSFontAttributeName];
NSMutableAttributedString * hrAttrString = [[NSMutableAttributedString alloc] initWithString:hrString attributes:hrDict];

UIFont * barcodeFont = [UIFont fontWithName:@IDAutomation DataBar 34size:22];
NSDictionary * barcodeDict = [NSDictionary dictionaryWithObject:barcodeFont forKey:NSFontAttributeName];
NSMutableAttributedString * barcodeAttrString = [[NSMutableAttributedString alloc] initWithString:alphaOnly attributes:barcodeDict];

[hrAttrString appendAttributedString:barcodeAttrString];

条形码字体正确显示,但ocr字体显示为系统字体。任何帮助将不胜感激。

解决方案



现在将字体设置为您的标签

  yourLabel.font = [UIFont fontWithName:@ocrbsize:15]; 


I am trying to use a truetype (.ttf) font in my iOS app and it is not working. I have added the font to my project and added the target correctly. I added the font in the info.plist under fonts provided by application. I am using an NSAttributedString to display text and this is my code

UIFont *hrFont = [UIFont fontWithName:@"ocrb" size:18.0];
NSDictionary *hrDict = [NSDictionary dictionaryWithObject:hrFont forKey:NSFontAttributeName];
NSMutableAttributedString *hrAttrString = [[NSMutableAttributedString alloc] initWithString:hrString attributes: hrDict];

UIFont *barcodeFont = [UIFont fontWithName:@"IDAutomation DataBar 34" size:22];
NSDictionary *barcodeDict = [NSDictionary dictionaryWithObject:barcodeFont forKey:NSFontAttributeName];
NSMutableAttributedString *barcodeAttrString = [[NSMutableAttributedString alloc]initWithString: alphaOnly attributes:barcodeDict];

[hrAttrString appendAttributedString:barcodeAttrString];

The barcode font displays correctly but the ocr font displays as the system font instead. Any help would be greatly appreciated.

解决方案

Now set font to your label

yourLabel.font = [UIFont fontWithName:@"ocrb" size:15];

这篇关于自定义字体不能在Xcode中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 09:39
查看更多