Swiftpack.co -  igooor-bb/JustPhotoPicker as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
igooor-bb/JustPhotoPicker
Simple and minimalistic photo picker for iOS written in Swift
.package(url: "https://github.com/igooor-bb/JustPhotoPicker.git", from: "1.1.0")

JustPhotoPicker

JustPhotoPicker is a simple and minimalistic photo picker for iOS written in Swift.

Initially, the project was made for personal purposes, but it was decided to make it publicly available for use and contribution in improvement.

Demo

Contents

Requirements

  • iOS/iPadOS 13.0+
  • Xcode 11.0+

Installation

Using CocoaPods

You can use CocoaPods to install JustPhotoPicker by adding folowing lines to your Podfile:

platform :ios, '13.0'
use_frameworks!

target 'ApplicationName' do
    pod 'JustPhotoPicker'
end

Then just write the command in the terminal to install:

$ pod install

Using Swift Package Manager

You can use Swift Package Manager to install JustPhotoPicker using Xcode:

  1. Open your project in Xcode
  2. Open "File" -> "Swift Packages" -> "Add Package Dependency..."
  3. Paste the repository URL: https://github.com/igooor-bb/JustPhotoPicker
  4. Click "Next" a couple of times and finish adding

Info.plist

To make your application have access to photos, add the following entity to the file Info.plist:

  • Privacy - Photo Library Usage Description
<key>NSPhotoLibraryUsageDescription</key>
<string>Some description</string>

Usage

First of all, import the module JustPhotoPicker into a file with your view controller:

import JustPhotoPicker

Configuration

You can change some visual and logical parameters using the JustPhotoPickerConfiguration structure. Set all the options you want and create a picker with configuration as a parameter:

var config = JustPhotoPickerConfiguration()
config.selectionLimit = 2
config.isSelectionRequired = true
// Configuration vibes...
let photoPicker = JustPhotoPicker(configuration: config)

Processing the result

Using the delegate

To obtain the selected photos or the fact that the photos were not selected, the JustPhotoPickerDelegate protocol can be used.

  1. Setup a delegate for your photo picker:
photoPicker.photoPickerDelegate = self
  1. Make your view controller conform the delegate protocol and implement both required methods:
extension ViewController: JustPhotoPickerDelegate {
  func didSelect(with photoPicker: JustPhotoPicker, images: [UIImage]) {
    print("Selected \(image.count) images")
  }

  func didNotSelect(with photoPicker: JustPhotoPicker) {
    print("Did not select any images")
  }
}

Using the closure

You also can use didFinishPicking closure of JustPhotoPicker class to obtain the selected photos:

let photoPicker = JustPhotoPicker(configuration: config)
photoPicker.didFinishPicking = { images, canceled in
  if canceled {
    print("Did not select any images")
    return
  }

  print("Selected \(images.count) images")
}

The closure takes two parameters. The first one is either a list of selected images or an empty list in case if a user did not select any. The second parameter is a boolean flag indicating whether a user canceled the selection.

Display

When you are ready to start picking photos, display the picker in the standard way:

present(photoPicker, animated: true)

Configuration properties

The following are some of the possible settings for the picker, which you can also find in the JustPhotoPickerConfigurationstructure:

config.selectionLimit = 2
config.isSelectionRequired = true
config.showsBottomDescriptionLabel = true
config.portraitModeCellsInRow = 3
config.landscapeModeCellsInRow = 6
config.backgroundColor = .white
config.accentColor = .systemPink
config.albumThumbnailCornerRaduis = 5
config.photoCardCornerRaduis = 0
config.startsOnScreen = .photos
config.hidesEmptyAlbumLabel = true
config.showsPhotoPreview = true
config.allowsPhotoPreviewZoom = false
// Configuration vibes...

Contribution

To contribute, use the follow "fork-and-pull" git workflow:

  1. Fork the repository on github
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a pull request so that I can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

License

JustPhotoPicker is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 1
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

Add closure for retrieving result of images selection
2 weeks ago

This version adds a public parameter didFinishPicking of the PhotoPicker class, which is a closure through which you can get the result of selecting images from the gallery:

let photoPicker = JustPhotoPicker(configuration: config)
photoPicker.didFinishPicking = { images, canceled in
    if canceled {
        print("Did not select any images")
        return
    }

    print("Selected \(images.count) images")
}
present(photoPicker, animated: true)

The JustPhotoPickerDelegate protocol used for the same purpose still continues to exist.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics