Giter Site home page Giter Site logo

irgallery-swift's Introduction

Build Status Platform

IRGallery-swift

  • IRGallery-swift is a powerful gallery for iOS.

Features

  • Captions.
  • Rotation support.
  • Load images locally or from a web URL.
  • Custom UITabBarItems.
  • Default UITabBarItems:
    • Delete.
    • Favorite.
    • Share.

Future

  • Single tap fullscreen mode.
  • Double tap image zooming.
  • Pinch zooming.

Install

Git

  • Git clone this project.
  • Copy this project into your own project.
  • Add the .xcodeproj into you project and link it as embed framework.

Options

  • You can remove the demo and ScreenShots folder.

Cocoapods

  • Add pod 'IRGallery-swift' in the Podfile
  • pod install

Usage

Basic

import IRGallery_swift

let galleryVC = IRGalleryViewController.init(photoSrc: self)
galleryVC.delegate = self
galleryVC.startingIndex = indexPath.row
galleryVC.useThumbnailView = false
galleryVC.gotoImageByIndex(UInt(indexPath.row), animated: false)
self.navigationController?.pushViewController(galleryVC, animated: true)
  • Use IRGalleryViewControllerSourceDelegate.
// MARK: - IRGalleryViewControllerDelegate
func numberOfPhotosForPhotoGallery(gallery: IRGalleryViewController) -> Int {
    return images.count
}

func photoGallery(gallery: IRGalleryViewController, sourceTypeForPhotoAtIndex index: UInt) -> IRGalleryPhotoSourceType {
    return .local
}

func photoGallery(gallery: IRGalleryViewController, captionForPhotoAtIndex index: UInt) -> String? {
    let filename = "Photo \(index + 1)"
    return filename
}

func photoGallery(gallery: IRGalleryViewController, filePathForPhotoSize size: IRGalleryPhotoSize, index: UInt) -> String? {
    let path = Bundle.main.url(forResource: images[Int(index)] as! String?, withExtension: nil)?.path
    return path
}

func photoGallery(gallery: IRGalleryViewController, urlForPhotoSize size: IRGalleryPhotoSize, index: UInt) -> String? {
    return nil
}

func photoGallery(gallery: IRGalleryViewController, isFavoriteForPhotoAtIndex index: UInt) -> Bool {
    return false
}

Advanced settings

  • Use IRGalleryViewControllerDelegate.
func photoGallery(gallery: IRGalleryViewController, deleteAtIndex index:UInt)
func photoGallery(gallery: IRGalleryViewController, addFavorite isAddToFavortieList: Bool, index: UInt)
  • Make your custome Bar Items.
var barItems: [UIBarButtonItem]

var deleteButton: UIBarButtonItem?
var favoriteButton: UIBarButtonItem?
var sendButton: UIBarButtonItem?

// create buttons for toolbar
let doDeleteButton = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 40, height: 50))
var image = UIImage.imageNamedForCurrentBundle(name: "btn_trash")
image = Utilities.image(image!, scaledToSize: CGSize.init(width: 20, height: 26.67))
doDeleteButton.setImage(image, for: .normal)
image = UIImage.imageNamedForCurrentBundle(name: "btn_trash")
image = Utilities.image(image!, scaledToSize: CGSize.init(width: 20, height: 26.67))
doDeleteButton.setImage(image, for: .highlighted)
doDeleteButton.addTarget(self, action: #selector(deleteClk), for: .touchUpInside)
self.deleteButton = UIBarButtonItem.init(customView: doDeleteButton)

let doFavoriteButton = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 40, height: 50))
image = UIImage.imageNamedForCurrentBundle(name: "btn_video_heart")
image = Utilities.image(image!, scaledToSize: CGSize.init(width: 21.4, height: 20))
doFavoriteButton.setImage(image, for: .normal)
image = UIImage.imageNamedForCurrentBundle(name: "btn_video_heart")
image = Utilities.image(image!, scaledToSize: CGSize.init(width: 21.4, height: 20))
doFavoriteButton.setImage(image, for: .highlighted)
image = UIImage.imageNamedForCurrentBundle(name: "btn_heart_h")
image = Utilities.image(image!, scaledToSize: CGSize.init(width: 21.4, height: 20))
doFavoriteButton.setImage(image, for: .selected)
doFavoriteButton.addTarget(self, action: #selector(addToMyFavoritesClk), for: .touchUpInside)
self.favoriteButton = UIBarButtonItem.init(customView: doFavoriteButton)

let doSendButton = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 40, height: 50))
image = UIImage.imageNamedForCurrentBundle(name: "btn_video_send")
image = Utilities.image(image!, scaledToSize: CGSize.init(width: 25, height: 25))
doSendButton.setImage(image, for: .normal)
image = UIImage.imageNamedForCurrentBundle(name: "btn_video_send")
image = Utilities.image(image!, scaledToSize: CGSize.init(width: 25, height: 25))
doSendButton.setImage(image, for: .highlighted)
doSendButton.addTarget(self, action: #selector(shareClk), for: .touchUpInside)
self.sendButton = UIBarButtonItem.init(customView: doSendButton)

barItems.insert(self.sendButton!, at: 0)
barItems.insert(self.favoriteButton!, at: 0)
barItems.insert(self.deleteButton!, at: 0)

...

let galleryVC = IRGalleryViewController.init(photoSrc: self, barItems: barItems)

Screenshots

List Gallery
List Gallery
Delete Favorite
Delete Favorite
Share Scale
Share Scale
Landscape
Landscape

irgallery-swift's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.