diff --git a/SwiftUIPractice/SwiftUIPractice.xcodeproj/project.pbxproj b/SwiftUIPractice/SwiftUIPractice.xcodeproj/project.pbxproj index f8df7c2..1320b76 100644 --- a/SwiftUIPractice/SwiftUIPractice.xcodeproj/project.pbxproj +++ b/SwiftUIPractice/SwiftUIPractice.xcodeproj/project.pbxproj @@ -9,23 +9,27 @@ /* Begin PBXBuildFile section */ 8928727C24B9AC7300799950 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8928727B24B9AC7300799950 /* AppDelegate.swift */; }; 8928727E24B9AC7300799950 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8928727D24B9AC7300799950 /* SceneDelegate.swift */; }; - 8928728024B9AC7300799950 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8928727F24B9AC7300799950 /* ContentView.swift */; }; + 8928728024B9AC7300799950 /* ImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8928727F24B9AC7300799950 /* ImageView.swift */; }; 8928728224B9AC7400799950 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8928728124B9AC7400799950 /* Assets.xcassets */; }; 8928728524B9AC7400799950 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8928728424B9AC7400799950 /* Preview Assets.xcassets */; }; 8928728824B9AC7400799950 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8928728624B9AC7400799950 /* LaunchScreen.storyboard */; }; + 897AD13B24C441420076DD13 /* SegmentedControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 897AD13A24C441420076DD13 /* SegmentedControlView.swift */; }; 89AFC52024C330EB005ABCDB /* StackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89AFC51F24C330EB005ABCDB /* StackView.swift */; }; + 89DE15D824D3E3820042E1D8 /* LoginScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89DE15D724D3E3820042E1D8 /* LoginScreenView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 8928727824B9AC7300799950 /* SwiftUIPractice.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftUIPractice.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8928727B24B9AC7300799950 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 8928727D24B9AC7300799950 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - 8928727F24B9AC7300799950 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 8928727F24B9AC7300799950 /* ImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageView.swift; sourceTree = ""; }; 8928728124B9AC7400799950 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 8928728424B9AC7400799950 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 8928728724B9AC7400799950 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 8928728924B9AC7400799950 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 897AD13A24C441420076DD13 /* SegmentedControlView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedControlView.swift; sourceTree = ""; }; 89AFC51F24C330EB005ABCDB /* StackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackView.swift; sourceTree = ""; }; + 89DE15D724D3E3820042E1D8 /* LoginScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginScreenView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -60,12 +64,14 @@ children = ( 8928727B24B9AC7300799950 /* AppDelegate.swift */, 8928727D24B9AC7300799950 /* SceneDelegate.swift */, - 8928727F24B9AC7300799950 /* ContentView.swift */, + 8928727F24B9AC7300799950 /* ImageView.swift */, 8928728124B9AC7400799950 /* Assets.xcassets */, 8928728624B9AC7400799950 /* LaunchScreen.storyboard */, 8928728924B9AC7400799950 /* Info.plist */, 8928728324B9AC7400799950 /* Preview Content */, 89AFC51F24C330EB005ABCDB /* StackView.swift */, + 897AD13A24C441420076DD13 /* SegmentedControlView.swift */, + 89DE15D724D3E3820042E1D8 /* LoginScreenView.swift */, ); path = SwiftUIPractice; sourceTree = ""; @@ -149,9 +155,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 897AD13B24C441420076DD13 /* SegmentedControlView.swift in Sources */, 8928727C24B9AC7300799950 /* AppDelegate.swift in Sources */, 8928727E24B9AC7300799950 /* SceneDelegate.swift in Sources */, - 8928728024B9AC7300799950 /* ContentView.swift in Sources */, + 8928728024B9AC7300799950 /* ImageView.swift in Sources */, + 89DE15D824D3E3820042E1D8 /* LoginScreenView.swift in Sources */, 89AFC52024C330EB005ABCDB /* StackView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/Nature2.imageset/Contents.json b/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/Nature2.imageset/Contents.json new file mode 100644 index 0000000..882949e --- /dev/null +++ b/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/Nature2.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Nature2.jpeg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/Nature2.imageset/Nature2.jpeg b/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/Nature2.imageset/Nature2.jpeg new file mode 100644 index 0000000..93a72d1 Binary files /dev/null and b/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/Nature2.imageset/Nature2.jpeg differ diff --git a/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/ferrari.imageset/Contents.json b/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/ferrari.imageset/Contents.json new file mode 100644 index 0000000..81e54eb --- /dev/null +++ b/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/ferrari.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "ferrari.jpg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/ferrari.imageset/ferrari.jpg b/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/ferrari.imageset/ferrari.jpg new file mode 100644 index 0000000..3dceaf7 Binary files /dev/null and b/SwiftUIPractice/SwiftUIPractice/Assets.xcassets/ferrari.imageset/ferrari.jpg differ diff --git a/SwiftUIPractice/SwiftUIPractice/ContentView.swift b/SwiftUIPractice/SwiftUIPractice/ImageView.swift similarity index 96% rename from SwiftUIPractice/SwiftUIPractice/ContentView.swift rename to SwiftUIPractice/SwiftUIPractice/ImageView.swift index 58c80af..50af1b4 100644 --- a/SwiftUIPractice/SwiftUIPractice/ContentView.swift +++ b/SwiftUIPractice/SwiftUIPractice/ImageView.swift @@ -8,7 +8,7 @@ import SwiftUI -struct ContentView: View { +struct ImageView: View { @State var scale: CGFloat = 1.0 @State private var half = false @State private var dim = false @@ -46,6 +46,6 @@ struct ContentView: View { struct ContentView_Previews: PreviewProvider { static var previews: some View { - ContentView() + ImageView() } } diff --git a/SwiftUIPractice/SwiftUIPractice/LoginScreenView.swift b/SwiftUIPractice/SwiftUIPractice/LoginScreenView.swift new file mode 100644 index 0000000..c300a85 --- /dev/null +++ b/SwiftUIPractice/SwiftUIPractice/LoginScreenView.swift @@ -0,0 +1,82 @@ +// +// LoginScreenView.swift +// SwiftUIPractice +// +// Created by Bhole, Kaustubh Satish on 31/07/20. +// Copyright © 2020 Bhole, Kaustubh Satish. All rights reserved. +// + +import SwiftUI + +struct LoginScreenView: View { + @State var email = "" + @State var password = "" + @State var loginBittonClick: Int? = nil + + var body: some View { + + NavigationView { + VStack(alignment: .leading) { + Text("Let's Login.") + .bold() + .font(.system(size: 40)) + .multilineTextAlignment(.leading) + .frame(width: 300, height: 100, alignment: .topLeading) + .padding(Edge.Set.bottom, 50) + + Text("Email address:") + .font(.headline) + TextField("Email", text: $email) + .frame(height:44) + .accentColor(Color.white) + .background(Color(UIColor.lightGray)) + .cornerRadius(4.0) + + Text("Password:") + .font(.headline) + + SecureField("Password", text: $password) + .frame(height:44) + .accentColor(Color.white) + .background(Color(UIColor.lightGray)) + .cornerRadius(4.0) + HStack { + Spacer() + Button(action: { + print("Forgot password tapped") + }) { + Text("Forgot Password?").foregroundColor(Color.gray).bold() + } + .accentColor(Color.black) + .padding(Edge.Set.vertical, 5) + } + Spacer() + NavigationLink(destination: SegmentedControlView(), tag: 1, selection: $loginBittonClick) { + Button(action: { + self.loginBittonClick = 1 + }) { + HStack { + Spacer() + Text("Login").foregroundColor(Color.white).bold() + Spacer() + } + } + .accentColor(Color.black) + .padding() + .background(Color(UIColor.red)) + .cornerRadius(20.0) + .padding(Edge.Set.vertical, 20) + } + Spacer() + } + .padding(.horizontal,30) + } + .navigationBarTitle(Text("Login")) + } +} + +struct LoginScreenView_Previews: PreviewProvider { + static var previews: some View { + LoginScreenView() + } +} diff --git a/SwiftUIPractice/SwiftUIPractice/SceneDelegate.swift b/SwiftUIPractice/SwiftUIPractice/SceneDelegate.swift index d0c0337..4f550ce 100644 --- a/SwiftUIPractice/SwiftUIPractice/SceneDelegate.swift +++ b/SwiftUIPractice/SwiftUIPractice/SceneDelegate.swift @@ -20,7 +20,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). // Create the SwiftUI view that provides the window contents. - let contentView = StackView() + let contentView = LoginScreenView() // Use a UIHostingController as window root view controller. if let windowScene = scene as? UIWindowScene { diff --git a/SwiftUIPractice/SwiftUIPractice/SegmentedControlView.swift b/SwiftUIPractice/SwiftUIPractice/SegmentedControlView.swift new file mode 100644 index 0000000..25e3568 --- /dev/null +++ b/SwiftUIPractice/SwiftUIPractice/SegmentedControlView.swift @@ -0,0 +1,106 @@ +// +// SegmentedControlView.swift +// SwiftUIPractice +// +// Created by Bhole, Kaustubh Satish on 19/07/20. +// Copyright © 2020 Bhole, Kaustubh Satish. All rights reserved. +// + +import SwiftUI + +struct SegmentedControlView: View { + @State private var selectedIndex = 0 + private let segmentItems = ["Nature","Birds","Cars"] + private let images = ["Nature2","bird1","ferrari"] + + var body: some View { + VStack { + Picker("", selection: $selectedIndex) { + ForEach(0 ..< segmentItems.count) { + Text(self.segmentItems[$0]) + } + }.pickerStyle(SegmentedPickerStyle()) + .padding(.all, 20) + .onReceive([self.selectedIndex].publisher.first()) { index in + switch index { + case 0: + print("First Tab selected") + case 1: + print("Second Tab selected") + default: + break + } + } + List { + ForEach (0...4, id: \.self) { contact in + NavigationLink(destination: Image(self.images[self.selectedIndex])) { + CellRow(selectedIndex: self.selectedIndex) + } + } + } + } + } +} + +struct CellRow: View { + var selectedIndex = 0 + + var body: some View { + containViews() + } + + func containViews() -> AnyView { + switch self.selectedIndex { + case 0: + return AnyView(ListRow(text: "Colors are the smiles of Nature", image: "Nature2")) + case 1: + return AnyView(ListRow(text: "A bird who dares to fall is the bird who learn to fly", image: "bird1")) + case 2: + return AnyView(ListRow(text: "No road is long with Good Company", image: "ferrari")) + default: + return AnyView(ListRow(text: "cars are just Awesome", image: "ferrari")) + } + } +} + +struct ListRow: View { + var text: String + var image: String + + var body: some View { + HStack { + VStack(alignment: .leading, spacing: 5) { + Text(text) + } + Image(image) + .resizable() + .scaledToFit() + .frame(height: 160, alignment: .center) + }.background(Color(.lightGray)) + + } +} + +struct Car: View { + var body: some View { + Image("ferrari") + .resizable() + .scaledToFit() + .frame(height: 160, alignment: .center) + } +} + +struct Nature: View { + var body: some View { + Image("Nature2") + .resizable() + .scaledToFit() + .frame(height: 160, alignment: .center) + } +} + +struct SegmentedControlView_Previews: PreviewProvider { + static var previews: some View { + SegmentedControlView() + } +} diff --git a/SwiftUIPractice/SwiftUIPractice/StackView.swift b/SwiftUIPractice/SwiftUIPractice/StackView.swift index cf1210e..7555aa0 100644 --- a/SwiftUIPractice/SwiftUIPractice/StackView.swift +++ b/SwiftUIPractice/SwiftUIPractice/StackView.swift @@ -33,23 +33,6 @@ struct StackView: View { } } -struct CellRow: View { - var body: some View { - HStack { - VStack(alignment: .leading, spacing: 10) { - Image("treeImage") - .frame(width: 100, height: 100, alignment: .center) - .clipShape(Circle()) - .padding(.leading, 20) - Text("Nature is So beautiful") - } - Image("bird1") - .resizable() - .frame(width: 160, height: 160, alignment: .center) - }.background(Color(.lightGray)) - } -} - struct StackView_Previews: PreviewProvider { static var previews: some View { StackView()