Sitemap

Member-only story

SwiftUI: How to make Toast and Notification Banners?

Xcode 12 — iOS 13+

2 min readFeb 20, 2021

Making Simple Overlay:

Notification and Toast views are basically an overlay view to existing view. To show an overlay, We will need a ZStack. this Zstack can wrap master View and below the overlay view and This overlay can be toggle via a bool.

In above code, the overlay takes the view which need to be shown on top of Main view and a binding object to show hide this view.

Now the second step would be to make the overlay view animatable.

Making Overlay view for a Banner:

Banner can be designed any way we like. But the main objective here is, how to hide and show it.

  • We are going to move banner from top to bottom with move transition.
.transition(AnyTransition.move(edge: .top).combined(with: .opacity))
  • we are going to add the logic to hide it on onAppear. so that banner can be dismissed after given time.

--

--

Prafulla Singh
Prafulla Singh

No responses yet