Skip to content

Instantly share code, notes, and snippets.

@grenos
Last active February 24, 2021 09:43
Show Gist options
  • Save grenos/2ebc41df627502233b814f0362eff011 to your computer and use it in GitHub Desktop.
Save grenos/2ebc41df627502233b814f0362eff011 to your computer and use it in GitHub Desktop.
swiftui-medium-004
struct GenericErrorView: View {
var image: String = "some-image-from-assets"
var title: String = "Title"
var subtitle: String = "Subtitle"
var buttonTitle: String = "ok"
var action: (() -> Void)?
var body: some View {
ZStack {
// here you can even put other views as background
VStack {
Image(image)
.resizable()
.aspectRatio(contentMode: .fiil)
.frame(width: 250, height: 200)
// text content
VStack {
Text(title)
.multilineTextAlignment(.center)
.padding()
Text(subtitle)
.multilineTextAlignment(.center)
.padding()
Spacer()
Button(action: action!) {
Text(buttonTitle)
.frame(width: 180, height: 45)
.foregroundColor(.white)
.background(.green)
.cornerRadius(5)
}
}
Spacer()
}
.frame(width: 200, height: 200)
.background(.white)
.cornerRadius(30, antialiased: true)
.shadow(radius: 20)
}
.edgesIgnoringSafeArea(.all)
}
}
struct GenericErrorView_Previews: PreviewProvider {
static var previews: some View {
GenericErrorView(image: "some-image-from-assets" , title: "Opps an error!", subtitle: "Subtitle!", buttonTitle: "ok ok")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment