Guest User

Untitled

a guest
Oct 6th, 2024
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.51 KB | Source Code | 0 0
  1. import PlaygroundSupport
  2. import SwiftUI
  3.  
  4. struct Toggles: View {
  5.     @State private var vibrateOnRing = false
  6.  
  7.     var body: some View {
  8.         VStack(spacing: 16) {
  9.             Toggle("Vibrate on Ring", isOn: $vibrateOnRing)
  10.  
  11.             Toggle(
  12.                 "Vibrate on Ring",
  13.                 systemImage: "dot.radiowaves.left.and.right",
  14.                 isOn: $vibrateOnRing
  15.             )
  16.  
  17.             Toggle("Vibrate on Ring", isOn: $vibrateOnRing)
  18.             .toggleStyle(.button)
  19.  
  20.             Toggle(isOn: $vibrateOnRing) {
  21.                 Text("Vibrate on Ring")
  22.                 Text("Enable vibration when the phone rings")
  23.             }
  24.             .toggleStyle(.switch)
  25.  
  26.             Toggle(isOn: $vibrateOnRing) {
  27.                 Text("Vibrate on Ring")
  28.                 Text("Enable vibration when the phone rings")
  29.             }
  30.             .toggleStyle(ChecklistToggleStyle())
  31.         }
  32.         .padding()
  33.     }
  34. }
  35.  
  36. struct ChecklistToggleStyle: ToggleStyle {
  37.     func makeBody(configuration: Configuration) -> some View {
  38.         Button {
  39.             configuration.isOn.toggle()
  40.         } label: {
  41.             HStack {
  42.                 Image(systemName: configuration.isOn
  43.                         ? "checkmark.circle.fill"
  44.                         : "circle")
  45.                 .tint(.green)
  46.                 configuration.label
  47.             }
  48.         }
  49.         .tint(.primary)
  50.         .buttonStyle(.borderless)
  51.     }
  52. }
  53.  
  54. let view = Toggles()
  55. PlaygroundPage.current.setLiveView(view)
Advertisement
Add Comment
Please, Sign In to add comment