-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SwiftUI HStack, VStack, List, Button & ScrollView
Worked on SwiftUI components like HStack, VStack, List, Button & ScrollView
- Loading branch information
1 parent
40c715f
commit 9e0dcaa
Showing
6 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+7.49 KB
(130%)
...odeproj/project.xcworkspace/xcuserdata/tkokate.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// CellRow.swift | ||
// SwiftUI_Starter | ||
// | ||
// Created by Kokate, Tejas on 19/07/20. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct CellRow: View { | ||
|
||
let cellData: ListModel | ||
|
||
var body: some View { | ||
HStack(spacing: 10) { | ||
Image(cellData.imageName) | ||
.resizable() | ||
.scaledToFill() | ||
.frame(width: 50, height: 50, alignment: .center) | ||
.cornerRadius(5) | ||
|
||
VStack(alignment: .leading, spacing: 3) { | ||
Text(cellData.title) | ||
.font(.headline) | ||
Text(cellData.subTitle) | ||
.font(.subheadline) | ||
} | ||
|
||
Spacer() | ||
|
||
Button(action: buttonAction) { | ||
Image(systemName: "chevron.right") | ||
.frame(width: 20, height: 20) | ||
.foregroundColor(Color.black) | ||
} | ||
} | ||
.padding(10) | ||
} | ||
|
||
private func buttonAction() { | ||
//TODO: week 4 | ||
} | ||
} | ||
|
||
struct CellRow_Previews: PreviewProvider { | ||
static var previews: some View { | ||
CellRow(cellData: ListModel(id: 1, title: "Title", subTitle: "SubTitle", imageName: "image1")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// ListModel.swift | ||
// SwiftUI_Starter | ||
// | ||
// Created by Kokate, Tejas on 19/07/20. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ListModel: Identifiable, Hashable { | ||
|
||
let id: Int | ||
let title: String | ||
let subTitle: String | ||
let imageName: String | ||
|
||
static func dummyData() -> [ListModel] { | ||
return [ListModel(id: 1, title: "Title 1", subTitle: "SubTitle 1", imageName: "image1"), | ||
ListModel(id: 2, title: "Title 2", subTitle: "SubTitle 2", imageName: "image2"), | ||
ListModel(id: 3, title: "Title 3", subTitle: "SubTitle 3", imageName: "image3"), | ||
ListModel(id: 4, title: "Title 4", subTitle: "SubTitle 4", imageName: "image1"), | ||
ListModel(id: 5, title: "Title 5", subTitle: "SubTitle 5", imageName: "image2"), | ||
ListModel(id: 6, title: "Title 6", subTitle: "SubTitle 6", imageName: "image3"), | ||
ListModel(id: 7, title: "Title 7", subTitle: "SubTitle 7", imageName: "image1"), | ||
ListModel(id: 8, title: "Title 8", subTitle: "SubTitle 8", imageName: "image2"), | ||
ListModel(id: 9, title: "Title 9", subTitle: "SubTitle 9", imageName: "image3"), | ||
ListModel(id: 10, title: "Title 10", subTitle: "SubTitle 10", imageName: "image1"), | ||
ListModel(id: 11, title: "Title 11", subTitle: "SubTitle 11", imageName: "image2"), | ||
ListModel(id: 12, title: "Title 12", subTitle: "SubTitle 12", imageName: "image3")] | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
SwiftUI_Starter/SwiftUI_Starter/List/MyFirstListView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// MyFirstListView.swift | ||
// SwiftUI_Starter | ||
// | ||
// Created by Kokate, Tejas on 19/07/20. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct MyFirstListView: View { | ||
var body: some View { | ||
NavigationView { | ||
List { | ||
ForEach(ListModel.dummyData(), id: \.self) { listObject in | ||
CellRow(cellData: listObject) | ||
} | ||
} | ||
.navigationBarTitle(Text("List View")) | ||
} | ||
} | ||
} | ||
|
||
struct MyFirstListView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
MyFirstListView() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
SwiftUI_Starter/SwiftUI_Starter/ScrollView/ScrollViewChallenge.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// ScrollViewChallenge.swift | ||
// SwiftUI_Starter | ||
// | ||
// Created by Kokate, Tejas on 19/07/20. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ScrollViewChallenge: View { | ||
var body: some View { | ||
NavigationView { | ||
ScrollView(.vertical, showsIndicators: true) { | ||
ForEach(ListModel.dummyData(), id: \.self) { listObject in | ||
CellRow(cellData: listObject) | ||
} | ||
} | ||
.navigationBarTitle(Text("List with Scroll View")) | ||
} | ||
} | ||
} | ||
|
||
struct ScrollViewChallenge_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ScrollViewChallenge() | ||
} | ||
} |