在更新到Swift 4之后,我得到了一个编译器错误:
Static member 'appearance' cannot be used on protocol metatype 'UIAppearance.Protocol'
这是我的自定义Tab Bar Controller子类中的viewWillAppear方法,我正在设置项目文本的字体。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// compiler error on line below
UIAppearance.appearance().setTitleTextAttributes([NSAttributedStringKey.font: font], for: UIControlState.normal)
}我在解决这个问题上遇到了麻烦,任何指导都将不胜感激,谢谢!
发布于 2017-07-26 05:35:44
对-当前的Swift 4转换工具(从Xcode9Beta4开始)有点失控。
通过恢复UIAppearance转换代码,然后更新各个属性,我能够快速解决这个问题。
例如,在Swift 3中,我有:
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.white], for: .selected)Xcode“帮助”了我,将它改为:
UIAppearance.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white], for: .selected)我能够通过半恢复来消除错误,如下所示:
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white], for: .selected)https://stackoverflow.com/questions/45150444
复制相似问题