Toggling Visibility with State
Show or hide views using a boolean state.
Show and Hide on Demand
A boolean @State can decide whether a view is visible. Flip it and SwiftUI shows or hides content for you. 👀
@State private var isVisible = falseConditional Views
Inside body you can use a plain if statement. When the condition is true, SwiftUI includes the view; when false, it leaves it out.
if isVisible {
Text("Now you see me")
}All lessons in this course
- Why Views Need State
- Declaring @State Properties
- Building a Tap Counter
- Toggling Visibility with State