gpt4 book ai didi

ios - 分配自定义字体时出现异常

转载 作者:行者123 更新时间:2023-11-29 00:18:57 24 4
gpt4 key购买 nike

我正在尝试在我的应用程序 GothamPro-NarrowMedium 中添加自定义字体我在项目中添加了 .otf 文件,在 info.plist 中添加了应用程序提供的字体并添加到目标成员中。现在,当我通过界面分配字体时,当我尝试将其添加到 NSMutableAttributedString 时,它可以完美运行,我得到以下异常

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]' * First throw call stack: (0x181ad6fe0 0x180538538 0x1819bd9b4 0x1819bd824 0x100075dac 0x100073fa8 0x187c07ec0 0x187c07a9c 0x187f975f0 0x187f5bce0 0x187f58130 0x187e94950 0x187e869ec 0x187bfa648 0x181a849a8 0x181a82630 0x181a82a7c 0x1819b2da4 0x18341c074 0x187c6d058 0x10011ff44 0x1809c159c) libc++abi.dylib: terminating with uncaught exception of type NSException

我的代码是

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = _lbl_mylabel.textAlignment;

NSDictionary *attribs = @{
NSForegroundColorAttributeName: self.lbl_ticketdetail.textColor,
NSFontAttributeName: self.lbl_ticketdetail.font
};
NSMutableAttributedString *attributedText =
[[NSMutableAttributedString alloc] initWithString:text
attributes:attribs];
paragraphStyle.lineSpacing = 3;

[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"GothamPro-NarrowMedium" size:20.0],NSParagraphStyleAttributeName:paragraphStyle}
range:cmp];

NSRange plce = [text rangeOfString:place];
[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"GothamPro-NarrowMedium" size:16.0],NSParagraphStyleAttributeName:paragraphStyle}
range:plce];

NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
paragraphStyle1.lineSpacing = 1;
NSRange tkt_num_range = [text rangeOfString:STR_tkt_num_club];
[attributedText setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"GothamMedium" size:13.0],NSParagraphStyleAttributeName:paragraphStyle1} range:tkt_num_range];
self.mylabel.attributedText = attributedText;

最佳答案

由于尝试将 null 对象插入 Dictionary 而发生崩溃。

我认为您在向项目中添加自定义字体时遇到了问题。

请重新检查

  1. Add .TTF font in your application.
  2. Add the key Fonts provided by application to a new row and add each .TTF file names.

完成这些步骤后,我猜你的 info.plist 可能是这样的:

<key>UIAppFonts</key>
<array>
<string>GothamMedium</string>
<string>GothamPro-NarrowMedium</string>
</array>

查找字体 PostScript 名称:

  • 打开字体簿
  • 选择字体
  • 查看 -> 显示字体信息 ( + I)
  • 复制PostScript 名称

关于ios - 分配自定义字体时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44536256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com