如何允许用户像 Telegram 应用程序一样在运行时自定义应用程序主题颜色、文本字体和文本字体大小?

穆罕默德·萨利赫

我的应用程序有一个设置屏幕,允许用户更改应用程序颜色,包括导航栏和标签栏的色调颜色,还允许他更改应用程序中所有文本的应用程序字体和字体大小,就像在 Telegram 应用程序中一样。问题是当用户为特定颜色列表选择颜色时,我需要重新加载或刷新我的应用程序,以使更改影响应用程序的选项卡栏和导航栏

我发现了这个问题,但它在应用程序启动时更改了一次颜色,但我希望允许用户自定义应用程序颜色和字体

在 Swift 中更改导航栏颜色

穆罕默德·萨利赫

经过长时间的搜索,我找到了解决用户选择特定颜色时在运行时更改导航栏和标签栏颜色,色调颜色和字体的问题的答案。

更改导航栏的颜色:使用它来更改当前屏幕导航栏的颜色

navigationController?.navigationBar.barTintColor = Color

以及更改整个应用程序中导航栏的颜色

UINavigationBar.appearance().tintColor = Color
UINavigationBar.appearance().barTintColor = Color

这用于更改当前屏幕的导航栏字体

navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: AppFont().large]

这适用于整个应用程序

UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: AppFont().large]

这用于更改标签栏色调颜色

self.tabBarController?.tabBar.tintColor = Color.theme.value

这可以更改标签栏项目字体

let selectedAttrs = [NSAttributedString.Key.font: Font, NSAttributedString.Key.foregroundColor: Color]

    if let items = self.tabBarController?.tabBar.items {
        for item in items {
            item.setTitleTextAttributes(selectedAttrs, for: .selected)
        }
    }

https://gph.is/g/ZOR7bAP

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章