Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created April 27, 2021 11:20
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 prafullakumar/e6bc091fd52dfd32cd3a30324e36155f to your computer and use it in GitHub Desktop.
Save prafullakumar/e6bc091fd52dfd32cd3a30324e36155f to your computer and use it in GitHub Desktop.
import SwiftUI
let buttonWidth: CGFloat = 60
enum CellButtons: Identifiable {
case edit
case delete
case save
case info
var id: String {
return "\(self)"
}
}
struct CellButtonView: View {
let data: CellButtons
let cellHeight: CGFloat
func getView(for image: String, title: String) -> some View {
VStack {
Image(systemName: image)
Text(title)
}.padding(5)
.foregroundColor(.primary)
.font(.subheadline)
.frame(width: buttonWidth, height: cellHeight)
}
var body: some View {
switch data {
case .edit:
getView(for: "pencil.circle", title: "Edit")
.background(Color.pink)
case .delete:
getView(for: "delete.right", title: "Delete")
.background(Color.red)
case .save:
getView(for: "square.and.arrow.down", title: "Save")
.background(Color.blue)
case .info:
getView(for: "info.circle", title: "Info")
.background(Color.green)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment