SwiftUI 设置状态栏、导航栏背景颜色

在使用List等基于tableview滚动界面的控件的时候,就会使得整个界面的颜色变成灰蒙蒙的,看了看页面结构,发现状态栏跟导航栏的颜色是透明色,因此显示出了后边tableview滚动默认的背景色。
因此为了解决使用List,From等控件是导致的导航栏颜色不太好看的问题,需要设置一下其背景色。
相应代码如下:

init() {
    // 设置状态栏颜色
    let tabbarAppearance = UITabBarAppearance()
    tabbarAppearance.configureWithOpaqueBackground()
    tabbarAppearance.backgroundColor = .white
    UITabBar.appearance().standardAppearance = tabbarAppearance
    
    // 设置导航栏颜色
    let navibarAppearance = UINavigationBarAppearance()
    navibarAppearance.configureWithOpaqueBackground()
    navibarAppearance.backgroundColor = .white
    UINavigationBar.appearance().standardAppearance = navibarAppearance
    UINavigationBar.appearance().scrollEdgeAppearance = navibarAppearance
}
IMG_3A55B68B9261-1.jpeg
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容