Ae Ri
Ae Ri

Reputation: 242

Page indicator in tabview swiftui

I'am using tabView to display some onboarding screens in my app. I was using

  .onAppear() {
                UIPageControl.appearance().currentPageIndicatorTintColor = .black
                UIPageControl.appearance().pageIndicatorTintColor = .gray
            }

to modify the background of the indicators and color. But now page indicator not showing in iOS 14.5 devices.

Referred this Link and other multiple links , but it says to add constraints. How to do that in swiftUI?

Upvotes: 0

Views: 2939

Answers (2)

SoftDesigner
SoftDesigner

Reputation: 5854

You can try a parameter to .tabViewStyle:

    TabView(selection: $selectedPage) {
        Text("1").tag(0)

        Text("2").tag(1)
    }
    .tabViewStyle(.page(indexDisplayMode: .never))

This way you don't change the appearance of all UIPageControl's in the app.

Upvotes: 1

Björn
Björn

Reputation: 370

Add an init() to the View where you define the UIKit appearance.

struct YourView: View {
    init() {
        UIPageControl.appearance().currentPageIndicatorTintColor = .black
        UIPageControl.appearance().pageIndicatorTintColor = .gray
    }

    var body: some View {
        // Text("YourView") with TabView
    }
}

Upvotes: 3

Related Questions