swiftswiftuiuipageviewcontrollerswiftui-tabview

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?


Solution

  • 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
        }
    }