Section 17 : Navigation View and List
- 导航视图和列表(11’48")
Build a table view with navigation options and presentations in SwiftUI.
在 SwiftUI 中使用导航选项和展示创建表格视图。
这一节内容依旧比较短,先新建一个 UpdateList.swift 文件。
1. 给导航视图创建数据模型
在 UpdateList 文件的末尾添加如下代码
// 模型
struct Update: Identifiable {var id = UUID()var image: Stringvar title: Stringvar text: Stringvar date: String
}
// 数据
let updateData = [Update(image: "Card1", title: "SwiftUI 进阶", text: "使用 API 数据、包和 CMS 等高阶技术将 SwiftUI app 发布到 App Store", date: "10月17日"),Update(image: "Card2", title: "Webflow", text: "使用高级互动、支付和 CMS 设计高度转换加载页面和制作动画", date: "12月31日"),Update(image: "Card3", title: "ProtoPie", text: "为移动端和网络端制作带有高级动画和交互的原型", date: "8月21日"),Update(image: "Card4", title: "SwiftUI", text: "使用 Xcode 11 对自定义UI、动画、手势和组件进行编程", date: "3月9日"),Update(image: "Card5", title: "Framer Playground", text: "使用 Framer X 代码编辑器创建强大的动画和交互", date: "11月11日"),Update(image: "Card6", title: "测试一个内容比较长的", text: "红军不怕远征难,万水千山只等闲。五岭逶迤腾细浪,乌蒙磅礴走泥丸。金沙水拍云崖暖,大渡桥横铁索寒。更喜岷山千里雪,三军过后尽开颜。", date: "10月1日")
]
2. 建立导航视图
很简单,直接上代码了
NavigationView { // 导航视图List(updateData) { update in // 更新信息列表,数据来自 updateDataNavigationLink(destination: Text(update.text)) { // 导航项目,目标为更新信息的详情HStack {Image(update.image) // 使用数据中的属性.resizable().aspectRatio(contentMode: .fit).frame(width: 80, height: 80).background(Color.black).cornerRadius(20).padding(.trailing, 4)VStack(alignment: .leading, spacing: 8) {Text(update.title).font(.system(size: 20, weight: .bold))Text(update.text).lineLimit(2).font(.subheadline).foregroundColor(Color(#colorLiteral(red: 0.501960814, green: 0.501960814, blue: 0.501960814, alpha: 1)))Text(update.date).font(.caption).fontWeight(.bold).foregroundColor(.secondary)}}.padding(.vertical, 8)}}.navigationBarTitle(Text("课程更新信息")) // 导航视图的标题}}
}
这样就完成了一个导航视图,页面顶端是 navigationBarTitle 修饰所给的标题。每条信息的概要在一行上显示,行末有 > 按钮,点击可以跳转到详情。详情页面有导航标题作为返回按钮。超过屏幕的部分可以向上滚动后显示。概要和详情相互切换时有内置的动画。下面是 NavigationLink 默认的创建代码。
NavigationLink(destination: Text("Destination")) { // 目标文字Text("Navigate") // 导航视图
}
//TODO:如果目标是视图该怎么办?
现在只是初步认识了导航视图,后面会陆续增加更深入的内容。
本节小结
本节代码请参见 GitHub 和 码云
- NavigationView 负责包裹导航视图的内容
- List 负责包裹一个列表
- NavigationLink 负责包裹一个导航项目,其中 destination 指明目的显示内容,后面的尾随闭包是导航条的内容
- navigationBarTitle 指明了组件的导航标题,注意这个修饰是加在 NavigationView 里面的组件上的,不是加在 NavigationView 上。
- 重复练习了 数据模型,数据引用,颜色字面量和其他一些修饰器。
接下来
导航样式
Section 17 : Navigation View and List相关推荐
- Html.BeginForm 与Section、Partial View 和 Child Action
该方法用于构建一个From表单的开始,他的构造方法为: Html.BeginForm("ActionName","ControllerName",FormMe ...
- (*长期更新)软考网络工程师学习笔记——Section 17 交换技术原理
目录 前言 一.交换机概述 (一)冲突域与广播域 1.冲突域 2.广播域 (二)交换机的基本概念 (三)交换机的分类 1.按管理划分 2.按工作层次划分 3.按网络拓扑结构划分 4.按交换机的交换方式 ...
- 软件工程 实践者的研究方法 第17章答案
Problem: Why is the "artistic ideal" an insufficient design philosophy when modern WebApps ...
- Collection View Programming Guide for iOS---(四)---Using the Flow Layout
Using the Flow Layout 使用流布局 The UICollectionViewFlowLayout class is a concrete layout object that yo ...
- ASP.NET MVC中如何以ajax的方式在View和Action中传递数据
前言:写这篇随笔的时候,在url上漏写了斜线,找了好久错误,整个人都很不好.#我是猪系列 背景:之前介绍过一篇如何构建ASP.NET MVC4&JQuery&AJax&JSon ...
- View Controller Programming Guide for iOS---(七)---Resizing the View Controller’s Views
Resizing the View Controller's Views A view controller owns its own view and manages the view's cont ...
- 17.1 Replication Configuration 复制:
17.1 Replication Configuration 复制:17.1.1 How to Set Up Replication 17.1.2 Replication Formats 17.1.3 ...
- Android--- Drawer and Tab Navigation with ViewPager
Android--- Drawer and Tab Navigation Tab Navigation --- View Pager+ Fragment + TabLayout 关于ViewPager ...
- HTML5 单页应用/框架 - View.js介绍
单页应用框架: View.js - http://view-js.com 什么是单页应用 单页应用,是指将用户视觉上的多个页面在技术上使用一个载体来实现的应用. 换句话来讲,用户视觉效果,与技术实现的 ...
最新文章
- Bootstrap框架中的字形图标的理解
- Http Tunnel 小记
- Unix/Linux环境C编程入门教程(41) C语言库函数的文件操作详解
- linux之vsftpd配置
- 1107 Social Clusters (30 分)【难度: 中 / 知识点: 并查集】
- 带你了解线缆、WIFI、以太网协议和网络寻址
- 台式计算机m9870t,JBT9870_水力测功器最新标准规范(14页)-原创力文档
- python编写接口初识一
- J - Borg Maze
- Laravel服务提供者在平台短信服务中的应用
- js拦截物联返回键跳转到指定页面
- Golang sync.Map 简介与用法
- ELK分析tomcat的Catalina.out日志
- 救急的戴尔Latitude 10商用平板电脑
- HTML5-打字游戏
- 计算机二级c语言程序设计答题流程,计算机二级C语言上机考试操作步骤及流程.doc...
- 阿里云ECS学习资源
- Sulley环境搭建
- word中添加背景色
- Python登录微信公众平台