ios - xcode 9 中的 IBanimitable 问题?

标签 ios swift xcode ios11 xcode9

我正在将 cocoapod 用于 ibanimatable。我之前将它与 xcode 一起使用并且工作正常。但是现在当我更新 pod 时它开始给我错误。

public extension PlaceholderDesignable where Self: UITextField {

  var placeholderText: String? { get { return "" } set {} }

  public func configurePlaceholderColor() {
    let text = placeholder ?? placeholderText
    if let placeholderColor = placeholderColor, let placeholder = text {
      attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [.foregroundColor: placeholderColor])
    }
  }
}

下面一行给我的错误是

 attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [.foregroundColor: placeholderColor])

类型“String”没有成员“foregroundColor”

请告诉我如何解决这个问题?

最佳答案

根据 here ,属性键不是在 String 中声明的,而是在 NSAttributedStringKey 中声明的。这意味着您不能使用方便的“只需在此处放一个点,编译器就会知道您的意思”语法糖。键是字符串,因此编译器认为您指的是 String.foregroundColor,但显然这样的东西不存在。

要解决此问题,请正确编写类型名称:

NSAttributedString(string: placeholder, attributes: [NSAttributedStringKey.foregroundColor: placeholderColor])

关于ios - xcode 9 中的 IBanimitable 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46904048/

相关文章:

ios - In App Purchase - 尝试再次购买消耗品时 - 此应用内购买已被购买

swift - 访问 RealmSwift 中的原始类型

ios - 仅在给定时间段内进行本地通知

xcode - 如何使用 cmake 将资源包添加到 xcode 项目中?

xcode - 在 SWIFT 中绘制圆弧进度

ios - ld : framework not found Crashlytics

ios - Swift Storyboard - 使用 calloutaccessorycontroltapped 公开按钮在 MapView 中创建一个 segue

iphone - UIScrollView 阻止我的 UIGesture 进行 View 转换

ios - UrbanAirship iOS SDK - 是否有通知权限请求回调?

swift - NSUserDefaults 已经有键值对了吗? - swift