Chi*_*ary 0 xcode fonts objective-c ios
我试图在我的iOS应用程序中使用truetype(.ttf)字体,但它无法正常工作.我已将字体添加到项目中并正确添加了目标.我在info.plist中添加了应用程序提供的字体下的字体.我使用NSAttributedString来显示文本,这是我的代码
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];
Run Code Online (Sandbox Code Playgroud)
条形码字体显示正确,但ocr字体显示为系统字体.任何帮助将不胜感激.
将自定义字体添加到项目中,即将字体文件(ocrb.TTF)拖动到XCode项目中.
编辑Info.plist:添加一个新条目,其中包含"应用程序提供的字体"键.
对于每个文件,将文件名添加到此数组
打开字体书中的字体(在finder中双击你的字体)看看真正的文件名是什么,我看到了:
现在将字体设置为标签
yourLabel.font = [UIFont fontWithName:@"ocrb" size:15];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1868 次 |
最近记录: |