首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIAppearance Swift 4

UIAppearance Swift 4
EN

Stack Overflow用户
提问于 2017-07-18 01:40:28
回答 1查看 11.4K关注 0票数 17

在更新到Swift 4之后,我得到了一个编译器错误:

Static member 'appearance' cannot be used on protocol metatype 'UIAppearance.Protocol'

这是我的自定义Tab Bar Controller子类中的viewWillAppear方法,我正在设置项目文本的字体。

代码语言:javascript
复制
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // compiler error on line below
    UIAppearance.appearance().setTitleTextAttributes([NSAttributedStringKey.font: font], for: UIControlState.normal)
}

我在解决这个问题上遇到了麻烦,任何指导都将不胜感激,谢谢!

EN

回答 1

Stack Overflow用户

发布于 2017-07-26 05:35:44

对-当前的Swift 4转换工具(从Xcode9Beta4开始)有点失控。

通过恢复UIAppearance转换代码,然后更新各个属性,我能够快速解决这个问题。

例如,在Swift 3中,我有:

代码语言:javascript
复制
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.white], for: .selected)

Xcode“帮助”了我,将它改为:

代码语言:javascript
复制
UIAppearance.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white], for: .selected)

我能够通过半恢复来消除错误,如下所示:

代码语言:javascript
复制
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white], for: .selected)
票数 33
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45150444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档