Skip to content

Instantly share code, notes, and snippets.

@shaundon
Created October 15, 2020 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaundon/85f5a3670bf005f5cd676656ed51ef09 to your computer and use it in GitHub Desktop.
Save shaundon/85f5a3670bf005f5cd676656ed51ef09 to your computer and use it in GitHub Desktop.
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