Created
October 15, 2020 14:56
-
-
Save shaundon/85f5a3670bf005f5cd676656ed51ef09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Heading: View { | |
let title: String | |
let accessoryView: AnyView? | |
init( | |
_ title: String, | |
accessoryView: AnyView? = nil | |
) { | |
self.title = title | |
self.accessoryView = accessoryView | |
} | |
var body: some View { | |
HStack { | |
Text(title).font(.title2).fontWeight(.semibold) | |
Spacer() | |
if let accessoryView = accessoryView { | |
accessoryView | |
} | |
} | |
.padding(.top, 20) | |
.padding(.bottom, 10) | |
} | |
} | |
struct Heading_Previews: PreviewProvider { | |
static var previews: some View { | |
VStack { | |
Heading("Default") | |
Heading("With an accessory view", accessoryView: AnyView(Color.blue.frame(width: 30, height: 30))) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment