自定义字体不能在Xcode中工作 [英] Custom Font not working in Xcode
问题描述
$ $ 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字体显示为系统字体。任何帮助将不胜感激。
将您的自定义字体添加到您的项目,即拖字体
文件( ocrb.TTF )转换为XCode项目。
$ b 编辑Info.plist:添加一个新的条目, strong>由
应用程序提供的字体。
对于每个文件,将文件名添加到该数组中b $ b
打开字体书中的字体(双击字体在finder中)到
查看真正的文件名是,我看到这个:
现在将字体设置为您的标签
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.
Add your custom font into your project , i.e. Dragged the font file(ocrb.TTF) into XCode project.
Edit Info.plist: Add a new entry with the key "Fonts provided by application".
For each of your files, add the file name to this array
Opened the font in font book(double click on your font in finder) to see what the real filename is and I see this:
Now set font to your label
yourLabel.font = [UIFont fontWithName:@"ocrb" size:15];
这篇关于自定义字体不能在Xcode中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!