SwiftUI came with very easy implementations in many type of areas in development. We can create onboarding view easily in few minutes far better than storyboard and UICollectionView.
So, I have created sample code for this.
Let’s Code!
First of all create card view for show sample image and title text.
Now add above CardView in the TabView and to give support of page view we can use modifier .tabViewStyle(.page)
For display page control we can use modifier .indexViewStyle(.page(backgroundDisplayMode: .always))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AKPageView.swift | |
// AKPageView | |
// | |
// Created by Ashish Kakkad on 31/08/23. | |
// | |
import SwiftUI | |
struct AKPageView: View { | |
var body: some View { | |
TabView() { | |
CardView(image: Image("Onboarding_1"), title: "It's best place to work!") | |
CardView(image: Image("Onboarding_2"), title: "Work mode on!") | |
} | |
.tabViewStyle(.page) | |
.indexViewStyle(.page(backgroundDisplayMode: .always)) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
AKPageView() | |
} | |
} |
That’s it! An amazing onboarding is ready.
Conclusion
Let me know if you have any questions, comments, or feedback – via Twitter.
Learn Something New. Share To The World.
Happy Coding 🙂