A custom SwiftUI ToggleStyle
for switching between light and dark mode.
- First, File → Swift Packages → Add Package Dependancy...
- Then, paste the repo link https://github.com/puthnith/SunMoonToggleStyle, then click Next and Finish
- Now add
import SunMoonToggleStyle
- And use it as
Toggle(...).toggleStyle(SunMoonToggleStyle())
struct ContentView: View {
@State private var isOn: Bool = false
var body: some View {
VStack {
Toggle(isOn: $isOn, label: label)
.toggleStyle(SunMoonToggleStyle())
}
.padding()
}
func label() -> Text {
isOn ? Text("Moon") : Text("Sun")
}
}
Inspired by Dribbble - Light / Dark mode toggle switcher