我是 Swift 的新手。我在 Swift 4 中创建了一个应用程序,但是当我将 SWIFT_VERSION 更改为 Swift 3.0 时,我的代码出现错误。
Type 'String' has no member 'foregroundColor'.
如何将其转换为当前的 Swift 语法?
代码:
if let p = placeholder {
let place = NSAttributedString(string: p, attributes: //error -->[.foregroundColor: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)])
attributedPlaceholder = place
textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
最佳答案
在 Swift 4 之前,带属性的字符串属性不是枚举。在这种情况下,您应该使用 NSForegroundColorAttributeName
。
NSAttributedString(string: p, attributes: [NSForegroundColorAttributeName: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)])
关于ios - 收到错误 : Type 'String' has no member 'foregroundColor' in Swift 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45422048/