CheckboxToggleStyle.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import SwiftUI
  2. struct CheckboxToggleStyle: ToggleStyle {
  3. func makeBody(configuration: Self.Configuration) -> some View {
  4. HStack {
  5. Circle()
  6. .stroke(lineWidth: 2)
  7. .foregroundColor(.secondary)
  8. .frame(width: 20, height: 20)
  9. .overlay {
  10. if configuration.isOn {
  11. Image(systemName: "circle.fill")
  12. }
  13. }
  14. .onTapGesture {
  15. withAnimation {
  16. configuration.isOn.toggle()
  17. }
  18. }
  19. configuration.label
  20. }
  21. }
  22. }
  23. struct Checkbox: ToggleStyle {
  24. func makeBody(configuration: Self.Configuration) -> some View {
  25. HStack {
  26. RoundedRectangle(cornerRadius: 5)
  27. .stroke(lineWidth: 2)
  28. .foregroundColor(.secondary)
  29. .frame(width: 20, height: 20)
  30. .overlay {
  31. if configuration.isOn {
  32. Image(systemName: "checkmark").font(.body).fontWeight(.bold)
  33. }
  34. }
  35. .onTapGesture {
  36. configuration.isOn.toggle()
  37. }
  38. configuration.label
  39. }
  40. }
  41. }