CheckboxToggleStyle.swift 671 B

123456789101112131415161718192021222324
  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. }