使用 ContentUnavailableView 添加不可用提示
了解如何使用 SwiftUI 中新的 ContentUnavailableView 组件,在应用程序中显示空状态。

ContentUnavailableView
是在 2023 年 WWDC 大会上随 iOS 17 一起推出的 SwiftUI 视图组件。主要用于展示某些功能不可用的提醒状态。
ContentUnavailableView | Apple Developer Documentation
An interface, consisting of a label and additional content, that you display when the content of your app is unavailable to users.


基本用法
ContentUnavailableView
组件和 Label
组件用法非常相似:
ContentUnavailableView(
"Connection issue",
systemImage: "wifi.slash"
)

还支持 description
参数,用于 添加格外的描述信息: