相关疑难解决方法(0)

NSFontAttributeName vs NSAttributedStringKey.font

我在使用一段时间的库中使用Swift代码时遇到了一些麻烦.它似乎与某种版本冲突有关,但我不确定.

这是代码:

let attribMsg = NSAttributedString(string: msg,
                               attributes: [NSAttributedStringKey.font:UIFont.systemFont(ofSize: 23.0)])
Run Code Online (Sandbox Code Playgroud)

这是我从编译器得到的错误消息:

Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'
    Did you mean 'zone'?  Fix(button)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在不同的项目中使用此代码,我注意到在其中一些我没有得到错误消息,它都编译没有任何问题.

我还注意到,如果我用以下代码替换上面的代码:

let attribMsg = NSAttributedString(string: msg,
                               attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 23.0)])
Run Code Online (Sandbox Code Playgroud)

有问题的项目将起作用,而其他项目(以前正在工作)显示此另一条消息:

'NSFontAttributeName' has been renamed to 'NSAttributedStringKey.font'
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

换句话说,一些项目使用一种类型的代码,而另一些项目使用另一种类型.

不用说,每次从一个项目切换到另一个项目时,我都不想更改代码.

我改变项目部署目标的实验似乎并没有太大的区别.我的问题就出现了:处理这个问题的方法是什么?

ios swift3

8
推荐指数
1
解决办法
1万
查看次数

使用未解析的标识符'NSFontAttributeName'

我将我的代码从swift 3.3迁移到4.1而且我收到了这个错误.我怎样才能解决这个问题 ?有什么建议?

progressView.titleLabelAttributedText = NSAttributedString(string: MyxStrings.sharedInstance.SENDING, attributes: [NSFontAttributeName: Scully.sharedInstance.APP_REGULAR_FONT_SMALL!])
Run Code Online (Sandbox Code Playgroud)

nsattributedstring ios swift

4
推荐指数
1
解决办法
2223
查看次数

标签 统计

ios ×2

nsattributedstring ×1

swift ×1

swift3 ×1