Day28:Update the Data and the Featured View

前言

今天要来更新 JSON data,
并且构建 the Featured view。

实作

  • 更新 data
  1. 用新的 JSON 文件替换之前的文件
    新的文件中的一组数据如下图:

    可以发现 ingredients 里的内容由 [Srting] 变成 多个 [Srting] 的集合,
    并新增了 highlights:[String]
  2. 进入 Models 新增及修改内容
var highlights:[String]
var ingredients:[Ingredients]
class Ingredients: Identifiable, Decodable {
    var id:UUID?
    var name:String
    var num:Int?
    var denom:Int?
    var unit:String?
}


3. 进入 DataService 给 Ingredients 设置 id

4. 进入 DetailView 修改显示的 ingredients
只需显示名字:

  • 补充 the FeaturedView
    我设想 the FeaturedView 将会是带有食谱的可以滑动更换的卡片
  1. 检查 JSON 文件,会发现有名为 "featured" 的 bool 值,
    如果显示为 true 则显示图片,
    false 则跳过。
  2. 为每个 "featured" == true 的 recipe 创建一个可滑动变换的矩形
TabView {
            ForEach (0..<model.recipes.count) {
                index in
                if model.recipes[index].featured == true {
                    Rectangle()
                }
            }
        }


在 Previews 添加环境修饰,以便於可以 canvas 可以呈现。
3. 改成可滑动式矩形

4. 用 GeometryReader 调整矩形大小并显示卡片下面的 indicator

5. 添加图像
先暂时 hardcode image 名称并将其图片和名字堆叠在这个矩形上:


6. 添加顶部及底部的文字


7. 换成多个 image 和 text


这样 the Featured View 就完成了。


<<:  [Day28] Linux Privilege Escalation

>>:  JavaScript DOM classList

[Day27] Room | 官方目前推荐不使用Sqlite

参考连结 先在build.gradle中加入以下这段 def room_version = &quo...

Day27-更改UIButton的Image大小,代志不是你想的这麽简单

上一篇提到设置了一个Sign In With Apple的按钮,是使用UIButton里面的Imag...

寻找mail server

各位大大好, 第一次发文, 想请教有无推荐的mail server,公司用,约100使用者, 有看过...

[Angular] Day25. Reactive forms (一)

上一篇中介绍完 Template-driven forms 後,接着再介绍 Angular 的另一种...

Day16 Loops(Ⅲ)

Loops的设计策略 ●Identify the statements that need to b...