Search code examples
swiftuiswiftui-tabview

TabView with wide images


Can you please tell me if there is a way to scroll through wide pictures normally? Without scrolling the part that doesn't fit on the screen?

Here is an example code:

import SwiftUI

struct ContentView: View {
    var body: some View {
        TabView {
            a_View()
            b_View()
        }
        .ignoresSafeArea()
        .tabViewStyle(.page)
    }
}

struct a_View: View {
    var body: some View {
        Image("Image1")
            .resizable()
            .scaledToFill()
            .ignoresSafeArea()
    }
}

struct b_View: View {
    var body: some View {
        Image("Image2")
            .resizable()
            .scaledToFill()
            .ignoresSafeArea()
    }
}

Here is a link to screen recording for clarity and both sample images in the attach:

screen recording

Image1

Image2


Solution

  • The solution:

    struct a_View: View {
        var body: some View {
            Image("AuthImage1")
                .resizable()
                .scaledToFill()
                .frame(width: UIScreen.main.bounds.width)
                .clipped()
                .ignoresSafeArea()
        }
    }