Last active
March 16, 2020 20:48
-
-
Save dbolella/60dfa7b3caff26f0d89e0a1fb977ed36 to your computer and use it in GitHub Desktop.
SwiftUI: Making Our Views More Dynamic and Reusable
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
import SwiftUI | |
struct ContentView: View { | |
var profile: Profile = Profile(name: "Danny", subtitle: "Awesome iOS Developer", description: "Danny loves SwiftUI and thinks it's the future of iOS Development!", profilePic: "profilepic") | |
var profile2: Profile = Profile(name: "George", subtitle: "An OK iOS Developer", description: "George should love SwiftUI and think that it's the future of iOS Development!", profilePic: "profilepic") | |
var body: some View { | |
VStack { | |
ProfilePage(profile: profile) | |
ProfilePage(profile: profile2) | |
} | |
} | |
} | |
struct ProfileInformation: View { | |
var profile: Profile | |
var body: some View { | |
VStack{ | |
Text(profile.name) | |
.font(.largeTitle) | |
Text(profile.subtitle) | |
.font(.title) | |
Text(profile.description) | |
.font(.body) | |
} | |
} | |
} | |
struct ProfilePage: View { | |
var profile: Profile | |
var body: some View { | |
VStack { | |
Image(profile.profilePic) | |
.resizable() | |
.aspectRatio(contentMode: .fit) | |
.clipShape(Circle()) | |
.overlay(Circle().stroke(Color.gray, lineWidth: 10)) | |
ProfileInformation(profile: profile) | |
} | |
.padding() | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
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
class Profile{ | |
var name: String = "" | |
var subtitle: String = "" | |
var description: String = "" | |
var profilePic: String = "" | |
init(name: String, subtitle: String, description: String, profilePic: String) { | |
self.name = name | |
self.subtitle = subtitle | |
self.description = description | |
self.profilePic = profilePic | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment