struct ToggleExample: View { @State private var agreeToTerms = false var body: some View { VStack { Text("DevTechie Terms and Conditions") Toggle("Agree", isOn: $agreeToTerms) } .padding() } }
struct ToggleExample: View { @State private var agreeToTerms = false var body: some View { VStack { Text("DevTechie Terms and Conditions") Toggle("Agree", isOn: $agreeToTerms) Button(action: {}) { HStack { Text("Continue") Image(systemName: "chevron.right.circle") } .padding() .background(.blue, in: Capsule()) .foregroundColor(agreeToTerms ? .primary : .gray) } .disabled(!agreeToTerms) } .padding() } }
struct ToggleExample: View { @State private var agreeToTerms = false var body: some View { VStack { Text("DevTechie Terms and Conditions") .padding(.bottom) VStack { Text("Agree?") .font(.title3.bold()) Toggle("Agree", isOn: $agreeToTerms) .labelsHidden() } Button(action: {}) { HStack { Text("Continue") Image(systemName: "chevron.right.circle") } .padding() .background(.blue, in: Capsule()) .foregroundColor(agreeToTerms ? .primary : .gray) } .disabled(!agreeToTerms) } .padding() } }
struct ToggleExample: View { @State private var agreeToTerms = false var body: some View { VStack { Text("DevTechie Terms and Conditions") .padding(.bottom) VStack { Text("Agree?") .font(.title3.bold()) Toggle(isOn: $agreeToTerms) { Image(systemName: agreeToTerms ? "hand.thumbsup.fill" : "hand.thumbsdown.fill") } .labelsHidden() .toggleStyle(.button) } Button(action: {}) { HStack { Text("Continue") Image(systemName: "chevron.right.circle") } .padding() .background(.blue, in: Capsule()) .foregroundColor(agreeToTerms ? .primary : .gray) } .disabled(!agreeToTerms) } .padding() } }
struct ToggleExample: View { @State private var agreeToTerms = false var body: some View { VStack { Text("DevTechie Terms and Conditions") .padding(.bottom) VStack { Text("Agree?") .font(.title3.bold()) Toggle(isOn: $agreeToTerms) { Image(systemName: agreeToTerms ? "hand.thumbsup.fill" : "hand.thumbsdown.fill") } .labelsHidden() .toggleStyle(.button) .tint(.green) } Button(action: {}) { HStack { Text("Continue") Image(systemName: "chevron.right.circle") } .padding() .background(.blue, in: Capsule()) .foregroundColor(agreeToTerms ? .primary : .gray) } .disabled(!agreeToTerms) } .padding() } }
struct ToggleExample: View { @State private var agreeToTerms = false var body: some View { VStack { Text("DevTechie Terms and Conditions") .padding(.bottom) VStack { Text("Agree?") .font(.title3.bold()) Toggle(isOn: $agreeToTerms) { Image(systemName: agreeToTerms ? "hand.thumbsup.fill" : "hand.thumbsdown.fill") } .toggleStyle(CustomToggle()) .labelsHidden() .tint(.green) } Button(action: {}) { HStack { Text("Continue") Image(systemName: "chevron.right.circle") } .padding() .background(.blue, in: Capsule()) .foregroundColor(agreeToTerms ? .primary : .gray) } .disabled(!agreeToTerms) } .padding() } }struct CustomToggle: ToggleStyle { let width: CGFloat = 50 func makeBody(configuration: Self.Configuration) -> some View { HStack { configuration.label ZStack(alignment: configuration.isOn ? .trailing : .leading) { Capsule() .frame(width: width, height: width / 2) .foregroundColor(configuration.isOn ? .green : .red) Capsule() .frame(width: (width / 2) - 4, height: width / 2 - 6) .padding(4) .foregroundColor(.white) .onTapGesture { withAnimation { configuration.$isOn.wrappedValue.toggle() } } } } } }
With that we have reached the end of this article. Thank you once again for reading. Don’t forget to subscribe to our weekly newsletter at