CheckboxToggleStyle.swift 1.3 KB

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