Pager in SwiftUI

Nicola De Filippo
2 min readDec 18, 2024

To help you with creating an onboarding screen using a custom pager with a custom font, custom color, and button, I’ll guide you through the steps:

Create the Pager Component:

  • The pager will typically be a component or a view that allows the user to swipe through different screens (each representing a step in the onboarding process).

Custom Font and Color:

  • To apply a custom font, first add the font files to your project. Then, set the font for the text elements in your pager screens.
  • For custom colors, define the color values (like hex codes or RGB) in your project’s color resources or stylesheet. Apply these colors to the text, background, or other elements as needed.

First, take a look how to create a pager:

TabView {
Text("First page")
Text("Second page")
Text("Third page")
}.tabViewStyle(.page)

Now see how add a font:

  • download Fredoka from here https://fonts.google.com/specimen/Fredoka
  • add it to the project select from the File menu “Add file to your project” and select the font file
  • write the font file mane in the info section “Font provided by application

Now add a custom color, in the project open assets and add color:

Set a name for the color and in the right panel set the color value.

Now create three views, using the custom color and the custom font, and please download also the san Francisco symbols (https://developer.apple.com/sf-symbols/) for the images.

struct ContentView: View {
var body: some View {
TabView {
VStack {
Image(systemName: "car")
.resizable()
.frame(width: 100, height: 100)
Text("Welcome - first screen")
.font(Font.custom("Fredoka-Regular", size: 30, relativeTo: .largeTitle))
}
VStack {
Image(systemName: "bolt.car")
.resizable()
.frame(width: 100, height: 100)
Text("Welcome - second screen")
.font(Font.custom("Fredoka-Regular", size: 30, relativeTo: .largeTitle))
}
}.tabViewStyle(.page)
.background(Color("onboardingColor"))
.foregroundStyle(.white)
}
}

Thus, we have the onboarding with the pager:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Nicola De Filippo
Nicola De Filippo

Written by Nicola De Filippo

Software Engineer and Entrepreneur

No responses yet

Write a response