在ios13上,使用iphone x时,大标题导航不会覆盖状态栏,但是当滚动并转换到传统导航栏时,它可以完美地工作.这不会影响没有槽口的设备.

大标题

Traditional navigation bar

这一切都嵌入了导航控制器中,所以我不知道为什么会发生这种情况.干杯

推荐答案

iOS 13之前,定制UINavigationBar的官方方式是:

// text/button color
UINavigationBar.appearance().tintColor = .white
// background color
UINavigationBar.appearance().barTintColor = .purple
// required to disable blur effect & allow barTintColor to work
UINavigationBar.appearance().isTranslucent = false

iOS 13改变了导航栏的工作方式,所以你需要做一些稍微不同的事情来支持旧的和;新的:

if #available(iOS 13.0, *) {
    let appearance = UINavigationBarAppearance()
    appearance.backgroundColor = .purple
    appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
    appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]

    UINavigationBar.appearance().tintColor = .white
    UINavigationBar.appearance().standardAppearance = appearance
    UINavigationBar.appearance().compactAppearance = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
    UINavigationBar.appearance().tintColor = .white
    UINavigationBar.appearance().barTintColor = .purple
    UINavigationBar.appearance().isTranslucent = false
}

Swift相关问答推荐

Swift concurrency reload/await,支持只执行成功并重试

如何在visionOS中进行购买?&# 39;购买(选项:)在visionOS中不可用

在Xcode SWIFT中运行用Ionic编写的函数

如何使 onKeyPress 与 TextField 快速配合使用?

SwiftUI如何能够在Text中使用字符串字面量来创建LocalizedStringKey?

暂停我的 AR 会话并清除变量和锚点的功能

如何在 SwiftUI 中创建条件内容?

我怎样才能缩短(提高效率)这段代码?

在 SwiftUI 中将属性显式设置为其默认值

UUID 哈希值是不确定的吗?

从 Int 到 String 的属性更改引发 SwiftUI 视图不更新

无法增加系统镜像的大小

如何以快速 Select 器菜单样式调整图像大小

Alamofire 会自动存储 cookie 吗?

如何在Swift中找出字母是字母数字还是数字

无法推断泛型参数的参数

Swift中字节数组的NSData

如何快速格式化用户显示(社交网络等)的时间间隔?

Xcode6 中的 Swift 类与 Cocoa Touch 类

Swift:长按手势识别器 - 检测轻按和长按