LBJImagePreviewer
is an image previewer implemented with SwiftUI.
- Zoom with magnification gesture
- Double click to zoom in/out
- Supports gif images
LBJImagePreviewer
can be installed using Swift Package Manager:
- Copy the package URL:
https://github.com/Lebron1992/LBJImagePreviewer
-
Open the menu
File / Add Packages
in Xcode. -
Paste the URL to the search box and add the library to your project.
Preview UIImage
:
let uiImage = UIImage(named: "lebron")!
LBJUIImagePreviewer(uiImage: uiImage)
Preview Image
:
// the width/height ratio of `Image` is needed
LBJImagePreviewer(content: Image(uiImage: uiImage), aspectRatio: 2 / 3)
Preview gif images:
LBJGIFImagePreviewer(imageNamed: "lebron")
if let url = Bundle.main.url(forResource: "lebron", withExtension: "gif"),
let data = try? Data(contentsOf: url) {
LBJGIFImagePreviewer(imageData: data)
}
If you don't preview an image with UIImage
or Image
, you could preview any View
. For example, we preview a red background:
LBJViewZoomer<Color>(content: .red, aspectRatio: 1)
You can specify the scale(3
by default) for double-tap to zoom in:
LBJUIImagePreviewer(uiImage: uiImage, doubleTapScale: 5)
LBJImagePreviewer(content: Image(uiImage: uiImage), aspectRatio: 2 / 3, doubleTapScale: 5)
Also you can specify the max scale(16
by default):
LBJUIImagePreviewer(uiImage: uiImage, maxScale: 20)
LBJImagePreviewer(content: Image(uiImage: uiImage), aspectRatio: 2 / 3, maxScale: 20)
Sets wheather reset the scale on disappear, true
by default:
LBJUIImagePreviewer(uiImage: uiImage, maxScale: 20)
.resetScaleOnDisappear(true)
LBJImagePreviewer(content: Image(uiImage: uiImage), aspectRatio: 2 / 3, maxScale: 20)
.resetScaleOnDisappear(false)
- When you double-click to zoom in, the image can ONLY be zoomed in from the middle, not at the click location. (Currently, we can't set
contentOffset
forScrollView
manually, so we have to wait for theScrollView
updates to solve the issue.)
Use GitHub issues to request a feature.