gpt4 book ai didi

ios - 如何使用 UIAppearance 设置 ViewController 的背景颜色

转载 作者:搜寻专家 更新时间:2023-11-01 06:02:17 25 4
gpt4 key购买 nike

我正在尝试使用 UIAppearance 来配置我的应用程序的样式。它与 UIView 或 UIButton 等 UI 组件完美配合,但不适用于 UIViewControllers。我想做类似的事情:

let appearance = FirstViewController.appearance()

有没有办法将 UIAppearance 与 ViewController 一起使用?

最佳答案

正如您在 documentation 中看到的那样UIAppearance 协议(protocol),只有两个类默认采用它,UIViewUIBarItem,因此 UIViewController 类有没有 appearance() 函数。

您可以通过实现协议(protocol)所需的方法来扩展 UIViewController,或者更简单的解决方案是创建您自己的 UIViewController 子类,它提供了一个默认类 view.backgroundColor 属性的颜色,并使所有 ViewController 继承自此类而不是直接继承 UIViewController

关于ios - 如何使用 UIAppearance 设置 ViewController 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46118012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com