SwiftUI—如何在PreviewProvider中使用导航视图

简介: SwiftUI—如何在PreviewProvider中使用导航视图

本节课演示如何在PreviewProvider中添加导航视图,从而将页面里的元素,可以在预览时显示在导航视图之中。


示例代码:


struct ContentView : View {
    var body: some View {
        VStack{
            Image("SwiftUI")
            .navigationBarTitle("About SwiftUI")
            Text("SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift. Build user interfaces for any Apple device using just one set of tools and APIs. With a declarative Swift syntax that’s easy to read and natural to write, SwiftUI works seamlessly with new Xcode design tools to keep your code and design perfectly in sync. Automatic support for Dynamic Type, Dark Mode, localization, and accessibility means your first line of SwiftUI code is already the most powerful UI code you’ve ever written.")
            .padding()
        }
    }
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        NavigationView { //将内容视图放置在NavigationView中里,从而预览当前页面位于导航视图里的效果
            ContentView()
        }
    }
}


2466108-74e639b8c9534e4c.webp.jpg


目录
相关文章
|
6月前
|
前端开发 搜索推荐 定位技术
GIS前端—Popup标注视图
GIS前端—Popup标注视图
48 0
|
7月前
|
容器
SAP UI5 视图里的 OverflowToolbar 控件
SAP UI5 视图里的 OverflowToolbar 控件
30 0
|
API iOS开发
SwiftUI 中的自定义导航
默认情况下,SwiftUI提供的各种导航API在很大程度上是以用户直接输入为中心的——也就是说,导航是在系统响应例如按钮的点击和标签切换等事件时由系统本身处理的。
227 0
SwiftUI 中的自定义导航
|
开发者 索引
SwiftUI极简教程27:DisclosureGroup拓展折叠视图的使用
SwiftUI极简教程27:DisclosureGroup拓展折叠视图的使用
483 0
SwiftUI极简教程27:DisclosureGroup拓展折叠视图的使用
|
定位技术
SwiftUI—使用MapKit里的地图视图
SwiftUI—使用MapKit里的地图视图
380 0
SwiftUI—使用MapKit里的地图视图
SwiftUI—如何给视图添加长按手势
SwiftUI—如何给视图添加长按手势
913 0
SwiftUI—如何给视图添加长按手势
SwiftUI—如何给视图添加单击手势
SwiftUI—如何给视图添加单击手势
236 0
SwiftUI—如何给视图添加单击手势
SwiftUI—如何使一个视图同时支持多种的手势
SwiftUI—如何使一个视图同时支持多种的手势
214 0
SwiftUI—如何使一个视图同时支持多种的手势
SwiftUI—如何给视图添加双击手势
SwiftUI—如何给视图添加双击手势
296 0
SwiftUI—如何给视图添加双击手势
SwiftUI—如何给视图添加拖动手势
SwiftUI—如何给视图添加拖动手势
512 0
SwiftUI—如何给视图添加拖动手势