Ios UI4
更新到Swift 4后,我收到一个编译器错误:Ios UI4,ios,swift,uiappearance,xcode9-beta,swift4,Ios,Swift,Uiappearance,Xcode9 Beta,Swift4,更新到Swift 4后,我收到一个编译器错误: 静态成员“外观”不能用于协议元类型“UIAppearance.protocol” 这是我的视图将出现在我的自定义选项卡栏控制器子类中的方法,我正在设置项目文本的字体 override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // compiler error on line below UIAppearance.appea
静态成员“外观”不能用于协议元类型“UIAppearance.protocol”
这是我的视图将出现在我的自定义选项卡栏控制器子类中的方法,我正在设置项目文本的字体
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// compiler error on line below
UIAppearance.appearance().setTitleTextAttributes([NSAttributedStringKey.font: font], for: UIControlState.normal)
}
我很难解决这个问题,任何指导将不胜感激,谢谢 右侧-当前的Swift 4转换工具(从Xcode 9 Beta 4开始)有点失控
通过还原ui外观
转换代码,然后更新各个属性,我能够快速修复问题
例如,在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)
那个代码应该做什么?通常,外观是为具体的UI类设置的,例如,UIBarItem.appearance().setTitleTextAttributes…
我将在问题中提供更多上下文。这是一个自定义选项卡栏控制器类,我正在更改栏项的字体。您需要从UI类调用,而不是直接从UIAppearance
调用。结果表明,当将代码从3更新为Swift 4时,Apple的助手引入了错误的代码。您应该在上报告,以便其他人不必处理它:)此处相同。迁移器正在将类型更改为UIAppearance,而不是UIAbbarItem、UIImageView等。您甚至可以省略NSAttributedStringKey,swift可以推断出来