-
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.
Week 3 - ScrollView, ListView and Stacks
- Loading branch information
Karan Bhasin
committed
Jul 16, 2020
1 parent
09d2792
commit 6af0db6
Showing
4 changed files
with
106 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
+4.25 KB
(120%)
...eproj/project.xcworkspace/xcuserdata/karbhasin.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,61 @@ | ||
// | ||
// CellRow.swift | ||
// SwiftUI_Starter | ||
// | ||
// Created by Karan Bhasin on 16/07/20. | ||
// Copyright © 2020 Karan Bhaisn. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
struct ListModel: Identifiable, Hashable { | ||
let id: Int | ||
let name: String | ||
let imageName: String | ||
|
||
static func data() -> [ListModel] { | ||
return [ListModel(id: 0, name: "Karan", imageName: "Bhasin"), | ||
ListModel(id: 0, name: "Nila", imageName: "Akash"), | ||
ListModel(id: 0, name: "Nitin", imageName: "Pant"), | ||
ListModel(id: 0, name: "Deepak", imageName: "Carpenter"), | ||
ListModel(id: 0, name: "Dileep", imageName: "M")] | ||
} | ||
} | ||
|
||
|
||
struct CellRow: View { | ||
let cellData: ListModel | ||
|
||
var body: some View { | ||
HStack(spacing: 10) { | ||
Text("Hello") | ||
Text(cellData.name) | ||
Button(action: buttonAction) { | ||
Image(systemName: "chevron.right") | ||
.frame(width: 20, height: 20) | ||
.foregroundColor(Color.yellow) | ||
} | ||
VStack { | ||
Text(cellData.imageName) | ||
Image("med") | ||
.resizable() | ||
.scaledToFill() | ||
.frame(width: 100, height: 100, alignment: .center) | ||
.clipShape(Rectangle()) | ||
.aspectRatio(contentMode: .fit) | ||
.clipped() | ||
} | ||
Spacer() | ||
} | ||
.background(Color.green) | ||
} | ||
|
||
private func buttonAction() { | ||
|
||
} | ||
} | ||
|
||
struct CellRow_Previews: PreviewProvider { | ||
static var previews: some View { | ||
CellRow(cellData: ListModel(id: 0, name: "lkjh", imageName: "jkhgj")) | ||
} | ||
} |
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,37 @@ | ||
// | ||
// ListView.swift | ||
// SwiftUI_Starter | ||
// | ||
// Created by Karan Bhasin on 16/07/20. | ||
// Copyright © 2020 Karan Bhaisn. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ListView: View { | ||
var body: some View { | ||
NavigationView { | ||
HStack(spacing: 5) { | ||
ScrollView { | ||
VStack(spacing: 15) { | ||
ForEach(ListModel.data(), id: \.self) { object in | ||
CellRow(cellData: object) | ||
} | ||
} | ||
} | ||
List { | ||
ForEach(ListModel.data(), id: \.self) { object in | ||
CellRow(cellData: object) | ||
} | ||
} | ||
} | ||
.navigationBarTitle("My List") | ||
} | ||
} | ||
} | ||
|
||
struct ListView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ListView() | ||
} | ||
} |