gpt4 book ai didi

ios - NSMutableAttributedString 使用自定义字体崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 05:55:19 26 4
gpt4 key购买 nike

<分区>

这很奇怪。

这个有效:

titleLabel.font = UIFont(name: "OpenSans-Regular", size: 14)

这个有效:

attributedString.addAttribute(NSFontAttributeName, value:
UIFont(name: "OpenSans-Bold", size: 18)!,
range: ((attributedString.string as NSString).range(of: "Forgot your password? Reset it here")))

这不是。崩溃:

Unexpectedly found nil while unwrapping an Optional value

attributedString.addAttribute(NSFontAttributeName, value:
UIFont(name: "OpenSans-Regular", size: 18)!,
range: ((attributedString.string as NSString).range(of: "Email or password are incorrect."))).

第一个示例表明 OpenSans-Regular 在应用程序中运行良好。 (与第 3 个示例中使用的字体相同)。

第二个示例显示属性字符串与自定义字体配合良好。

第三个示例显示带有自定义字体的属性字符串不起作用。

我仔细检查了 OpenSans-Regular 我在我的项目中正确复制了:

项目目录:

enter image description here .

复制资源包:

enter image description here

信息.plist:

enter image description here .

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