9
9
import SwiftUI
10
10
11
11
struct HomeList : View {
12
+
13
+ var courses = coursesData
14
+
12
15
var body : some View {
13
16
ScrollView ( . horizontal, showsIndicators: false ) {
14
- HStack {
15
- ForEach ( /*@START_MENU_TOKEN@*/0 ..< 5 /*@END_MENU_TOKEN@*/) { _ in
16
- CourseView ( )
17
+ HStack ( spacing: 30.0 ) {
18
+ ForEach ( courses) { item in
19
+ PresentationLink ( destination: ContentView ( ) ) {
20
+ CourseView ( title: item. title,
21
+ image: item. image,
22
+ color: item. color,
23
+ shadowColor: item. shadowColor)
24
+ }
17
25
}
18
26
}
27
+ . padding ( . leading, 30 )
19
28
Spacer ( )
20
29
}
21
30
}
@@ -30,23 +39,53 @@ struct HomeList_Previews: PreviewProvider {
30
39
#endif
31
40
32
41
struct CourseView : View {
42
+
43
+ var title = " Build an app with SwiftUI "
44
+ var image = " Illustration1 "
45
+ var color = Color ( " background3 " )
46
+ var shadowColor = Color ( " backgroundShadow3 " )
47
+
33
48
var body : some View {
34
49
return VStack ( alignment: . leading) {
35
- Text ( " Build an app with SwiftUI " )
50
+ Text ( title )
36
51
. font ( /*@START_MENU_TOKEN@*/ . title/*@END_MENU_TOKEN@*/)
37
52
. fontWeight ( /*@START_MENU_TOKEN@*/ . bold/*@END_MENU_TOKEN@*/)
38
53
. color ( . white)
39
54
. padding ( 20 )
40
55
. lineLimit ( 4 )
41
- . frame ( width : 150 )
56
+ . padding ( . trailing , 50 )
42
57
43
58
Spacer ( )
44
59
45
- Image ( " Illustration1 " )
60
+ Image ( image)
61
+ . resizable ( )
62
+ . renderingMode ( . original)
63
+ . aspectRatio ( contentMode: . fit)
64
+ . frame ( width: 246 , height: 200 )
65
+ . padding ( . bottom, 30 )
46
66
}
47
- . background ( Color ( " background3 " ) )
67
+ . background ( color )
48
68
. cornerRadius ( 30 )
49
69
. frame ( width: 246 , height: 360 )
50
- . shadow ( color: Color ( " backgroundShadow3 " ) , radius: 20 , x: 0 , y: 20 )
70
+ . shadow ( color: shadowColor , radius: 20 , x: 0 , y: 20 )
51
71
}
52
72
}
73
+
74
+ struct Course : Identifiable {
75
+ var id = UUID ( )
76
+ var title : String
77
+ var image : String
78
+ var color : Color
79
+ var shadowColor : Color
80
+ }
81
+
82
+ let coursesData = [
83
+ Course ( title: " Build an app with SwiftUI " ,
84
+ image: " Illustration1 " ,
85
+ color: Color ( " background3 " ) ,
86
+ shadowColor: Color ( " backgroundShadow3 " ) ) ,
87
+ Course ( title: " Design Course " ,
88
+ image: " Illustration2 " ,
89
+ color: Color ( " background4 " ) ,
90
+ shadowColor: Color ( " backgroundShadow4 " ) )
91
+ ]
0 commit comments