SwiftUI Image Viewer with zoom, drag to dismiss, URL and local images image
  • July 21, 2025

Summary


An image viewer built using SwiftUI. Featuring drag to dismiss, pinch to zoom, remote and local images, and more.

image

Installation via Swift Package Manager


File > Swift Packages > Add Package Dependancy

https://github.com/Jake-Short/swiftui-image-viewer.git

Usage


Local Image:

The image parameter accepts Binding<Image> in all versions. As of 1.0.20, it also accepts Binding<Image?>

 

import ImageViewer

 

struct ContentView: View {

@State var showImageViewer: Bool = true

@State var image = Image(“example-image”)

 

var body: some View {

VStack {

Text(“Example!”)

}

.frame(maxWidth: .infinity, maxHeight: .infinity)

.overlay(ImageViewer(image: self.$image, viewerShown: self.$showImageViewer))

}

}

Remote Image:

The imageURL parameter accepts Binding<String>

import ImageViewerRemote
struct ContentView: View {
    @State var showImageViewer: Bool = true
    @State var imgURL: String = “https://…”
    var body: some View {
        VStack {
            Text(“Example!”)
        }
.frame(maxWidth: .infinity, maxHeight: .infinity)
        .overlay(ImageViewerRemote(imageURL: self.$imgURL, viewerShown: self.$showImageViewer))
    }
}

Customization


close Button Position

Availability: 2.2.0 or higher

The close button can be moved to the top right if desired. The closeButtonTopRight parameter accepts bool.

Example:

import ImageViewer

struct ContentView: View {
@State var showImageViewer: Bool = true
@State var image = Image(“example-image”)

var body: some View {
VStack {
Text(“Example!”)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.overlay(ImageViewer(image: self.$image, viewerShown: self.$showImageViewer, closeButtonTopRight: true))
}
}

Caption

Availability: 2.1.0 or higher

A caption can be added to the image viewer. The caption will appear near the bottom of the image viewer (if the image fills the whole screen the text will appear on top of the image). The caption parameter accepts Text.

Example:

import ImageViewer

 

struct ContentView: View {

@State var showImageViewer: Bool = true

@State var image = Image(“example-image”)

 

var body: some View {

VStack {

Text(“Example!”)

}

.frame(maxWidth: .infinity, maxHeight: .infinity)

.overlay(ImageViewer(image: self.$image, viewerShown: self.$showImageViewer, caption: Text(“This is a caption!”)))

}

}

Explicit Aspect Ratio

Availability: 1.0.21 or higher

An explcit image aspect ratio can be specified, which fixes an issue of incorrect stretching that occurs in certain situations. The aspectRatio parameter accepts Binding<CGFloat>

Example:

import ImageViewer
struct ContentView: View {
    @State var showImageViewer: Bool = true
    @State var image = Image(“example-image”)
    var body: some View {
        VStack {
            Text(“Example!”)
        }
.frame(maxWidth: .infinity, maxHeight: .infinity)
        .overlay(ImageViewer(image: self.$image, viewerShown: self.$showImageViewer, aspectRatio: .constant(2)))
    }
}

Disable Cache

Availability: 1.0.25 or higher

To disable cache on the remote image viewer, simply pass a Bool value to the disableCache parameter

Example:

import ImageViewerRemote
struct ContentView: View {
    @State var showImageViewer: Bool = true
    var body: some View {
        VStack {
            Text(“Example!”)
        }
.frame(maxWidth: .infinity, maxHeight: .infinity)
        .overlay(ImageViewerRemote(imageURL: URL(string: “https://…”), viewerShown: self.$showImageViewer, disableCache: true))
    }
}

GitHub


View Github

#images #photogallery
YOU MIGHT ALSO LIKE...
SwiftSpeech

Recognize your user's voice elegantly without having to figure out authorization and audio engines. SwiftSpeech Examples Features Installation Getting Started ...

SwiftUIValueSlider

Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 14.0 Installation ...

Sliders

Sliders is a compilation of all my stylable drag based SwiftUI components. It provides a variety of unique controls as well ...

SlidingRuler

SlidingRuler is a Swift package containing a SwiftUI control that acts like an linear infinite slider or a finite, more precise ...

Skeletonui

SkeletonUI aims to bring an elegant, declarative syntax to skeleton loading animations. Get rid of loading screens or spinners and ...