【发布时间】:2018-03-13 05:12:48
【问题描述】:
【问题讨论】:
-
分享您的 pod 信息和 swift 语言版本。你已经为 swift3 添加了一个标签,那么它到底是 swift3 还是 swift3.x?
标签: ios swift3 cocoapods nsattributedstring cosmos
【问题讨论】:
标签: ios swift3 cocoapods nsattributedstring cosmos
注意:确保项目的 swift 语言版本。以下是您如何查看/检查您的 swift 语言版本的方法。
您有两个选项可以作为您的查询的解决方案:
如果您的项目有 Swift 4.0 版
- 您应该选择/下载与您项目的 swift 语言兼容的 POD(分享我 POD 信息和 swift 版本,以便我可以为您提供适合项目的 pod 库的确切 pod 版本)。
如果您的项目的 swift 版本低于 4.0
- 您需要将您的项目迁移到 Swift 4.0(如果您尚未迁移它)。这是参考问答,如何从 swift(下)
根据您在问题中添加的标签 - Swift3 是您当前的项目语言版本和 pod 'Cosmos','~> 12.0' 支持 swift 4。
pod 'Cosmos', '~> 12.0'
这里是支持 Swift 4.0 以下版本的先前版本列表。
https://github.com/evgenyneu/Cosmos/releases
尝试以前版本的 cosmos,例如:
pod 'Cosmos', '~> 11.0.3'
// or
pod 'Cosmos', '~> 11.0.1'
// or
pod 'Cosmos', '~> 11.0.0
'
【讨论】:
attributes: [NSFontAttributeName: label.font]
swift 3.2 似乎没问题。 我修复了分页菜单视图控制器库。
【讨论】:
就我而言 我替换此代码
[NSAttributedStringKey.font : font]
通过下面的代码
.size(attributes: [NSFontAttributeName : font])
希望对你有帮助。
【讨论】:
您必须需要将 swift 版本从 Xcode 更新到 4.0。
使用下面的步骤
1) 从项目经理那里选择您的项目(Xcode 左上角)
2) 选择构建设置
3) 搜索“Swift 语言”
4) 更改“Swift 语言版本” => Swift 4.0
【讨论】:
let label = UILabel()
label.font = UIFont.preferredFont(forTextStyle: .subheadline)
【讨论】:
let percentOff = NSMutableAttributedString(string: "\(productOff ?? "0")%OFF",
attributes: [NSFontAttributeName: UIFont(name: "Montserrat-Regular",
size: 13)!,NSForegroundColorAttributeName: UIColor.black,
NSBackgroundColorAttributeName: UIColor.black])
lblPriceDetail.attributedText = percentOff
这在 swift 4.2 中对我有用
【讨论】:
您的 pod 可能有错误的 swift 版本,而不是项目设置。
要更改 pod swift 设置,请在文件导航器(屏幕左侧)中转到 Pod(蓝色图标),然后选择您遇到问题的 pod。然后转到构建设置并转到 Swift 语言版本。选择 Swift 4。
【讨论】: