Custom Toggle / Checkbox in SwiftUI
Reading time: 1 min
This recipe shows how to implement a custom Toggle
via ToggleStyle
. The particular ToggleStyle
you'll implement will make a Toggle
look like a checkbox. The end result will look like this:
OK, here's the code for the custom ToggleStyle
. It maps the ToggleStyleConfiguration
onto a...
Introducing SwiftUI Recipes Companion!
Reading time: 2 min
Here at SwiftUIRecipes.com, we're proud to announce the SwiftUI Recipes Companion app!
This FREE app allows you to view community-sourced recipes and includes an XCode Source Editor extension, allowing you to insert the recipe code straight into your own!
You can preview its content and...
Reading time: 2 min
This recipe shows how to show multiple Alert
s, ActionSheet
s or custom dialogs, without tying them to multiple views. The end result looks like this:
The usual way of using multiple views has its shortcomings, as it:
- Forces you to have at least as many views as distinct modals you wish...
Stroke and fill a Shape in SwiftUI
Reading time: 1 min
For whatever reason, stroking (i.e drawing a border) and filling a SwiftUI Shape
at the same time is difficult and unintuitive. Shape
has methods for both, stroke
and fill
, respectively, but they both return some View
, meaning you can't chain them.
Say you want to do the following:
T...
Custom Slider in SwiftUI
Reading time: 6 min
This recipe shows how to implement a custom Slider in SwiftUI. The default Slider
view isn't particularly customisable, so any stepping outside the norm requires custom code.
Here's what the end result will look like:
- On the top you have the default
Slider
. - In the middle there's our cust...