Learning w/ Swift

Scrollable Gallaries in SwiftUI

TabView in SwiftUI makes creating scrolling galleries a breeze when combined with the optional .tabViewStyle(PageTabViewStyle()) modifier.

In this example I overwrote the default appearance of the page indicators by running a simple function when the view appears so that the indicator dots are visible on a white background.


import SwiftUI

struct ImageSlider: View {
    private let images = ["Barbie", "Oppenheimer", "Blue Beetle", "Haunted Mansion", "Mission Impossible"]
    var body: some View {
        TabView {
            ForEach(images, id: \.self) { item in
        .frame(maxHeight: 650)
        .onAppear {
    func setupAppearance() {
        UIPageControl.appearance().currentPageIndicatorTintColor = .black
        UIPageControl.appearance().pageIndicatorTintColor = UIColor.black.withAlphaComponent(0.2)