Use the .disabled modifier on views to deactivate any elements with a boolean value set to true.
Category Archives: swiftui
How to detect tap gestures in SwiftUI
Use the handy onTapGesture method to recognize taps on views.
How to detect a dragging motion with DragGesture in SwiftUI
Use the DragGesture struct within a .gesture modifier to detect any type of dragging motion alongside the methods of .onChanged and .onEnded with the DragGesture.
How to make views disappear in SwiftUI with DispatchQueue
You can make views disappear after some delay by utilizing the DispatchQueue to schedule async work after some amount of time which toggles a boolean value to make a view appear or disappear.
How to set the size of SF Symbols in SwiftUI?
Because SF Symbols are similar to fonts you can set the size directly with the .font modifier and passing in a size.
How to present a modal view with Sheet in SwiftUI
A modal view is known as a Sheet in SwiftUI. You can use the method on views to open up a sheet on top of the view it’s attached on by passing in a boolean variable binding, optionally a closure to run when dismissed and the view to show in the modal.
How to use Picker in SwiftUI?
Using the Picker struct you can build out your own view to let users select from a set of items by passing in a label, variable to bind the selection, and the data and views to compute from e.g. content.
How to rotate views in SwiftUI?
You can rotate views by some number of degrees using the .rotationEffect method.
How to create a Button in SwiftUI?
You can use the built-in Button struct to create tappable buttons in SwiftUI. Each Button takes in an action to fire e.g. printing to the console, and a View to render for the button (like a Text() field!).
How to create a half circle in SwiftUI?
You can use the built-in .trim() modifier in SwiftUI to create parts of Shape! The .trim() modifier takes two parameters from: and to: which take in CGFloat.