Bottom Sheet Tutorial in iOS 18 – #30DaysOfSwift

In the second post of #30DaysOfSwift series, you will learn how to add a bottom sheet.


This content originally appeared on HackerNoon and was authored by Vaibhav

Day 1: Stumbling across the Hidden Gold 👑

\ In the second post of #30DaysOfSwift series, you will learn how to add a bottom sheet.

\ With a Fab-ulous button to toggle the sheet, you can show your content inside it.

\ Here's a sneak peek of the inspiration for this sheet:

Image description

\ Ready to dive into the code? Here it is:

\ Image description

\ Or you can just copy it from here:

@State var shouldPresentSheet = false

    var body: some View {
        VStack {
          // ...
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
            .overlay(
                VStack {
                    Spacer() // Pushes the button to the bottom
                    HStack {
                        Spacer() // Pushes the button to the right
                        Button(action: {
                            shouldPresentSheet.toggle() // Toggles sheet On/Off
                        }) {
                            Image(systemName: "plus")
                                .foregroundColor(.white)
                                .padding()
                                .background(Color(.orange))
                                .clipShape(Circle())
                                .shadow(color: Color(.gray), radius: 2.5)
                        }
                        .sheet(isPresented: $shouldPresentSheet) {
                            print("Sheet dismissed!")
                        } content: {
                            Text("In the sheets!")
                        }
                        .padding()
                    }
                }
                .frame(maxWidth: .infinity, maxHeight: .infinity)
            )
    }

\ Let me know how you plan to use it in your App. Feel free to comment below if there are any doubts.

\ Happy coding!


This content originally appeared on HackerNoon and was authored by Vaibhav


Print Share Comment Cite Upload Translate Updates
APA

Vaibhav | Sciencx (2024-10-03T01:10:26+00:00) Bottom Sheet Tutorial in iOS 18 – #30DaysOfSwift. Retrieved from https://www.scien.cx/2024/10/03/bottom-sheet-tutorial-in-ios-18-30daysofswift/

MLA
" » Bottom Sheet Tutorial in iOS 18 – #30DaysOfSwift." Vaibhav | Sciencx - Thursday October 3, 2024, https://www.scien.cx/2024/10/03/bottom-sheet-tutorial-in-ios-18-30daysofswift/
HARVARD
Vaibhav | Sciencx Thursday October 3, 2024 » Bottom Sheet Tutorial in iOS 18 – #30DaysOfSwift., viewed ,<https://www.scien.cx/2024/10/03/bottom-sheet-tutorial-in-ios-18-30daysofswift/>
VANCOUVER
Vaibhav | Sciencx - » Bottom Sheet Tutorial in iOS 18 – #30DaysOfSwift. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/03/bottom-sheet-tutorial-in-ios-18-30daysofswift/
CHICAGO
" » Bottom Sheet Tutorial in iOS 18 – #30DaysOfSwift." Vaibhav | Sciencx - Accessed . https://www.scien.cx/2024/10/03/bottom-sheet-tutorial-in-ios-18-30daysofswift/
IEEE
" » Bottom Sheet Tutorial in iOS 18 – #30DaysOfSwift." Vaibhav | Sciencx [Online]. Available: https://www.scien.cx/2024/10/03/bottom-sheet-tutorial-in-ios-18-30daysofswift/. [Accessed: ]
rf:citation
» Bottom Sheet Tutorial in iOS 18 – #30DaysOfSwift | Vaibhav | Sciencx | https://www.scien.cx/2024/10/03/bottom-sheet-tutorial-in-ios-18-30daysofswift/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.