LibraryController

@objcMembers
public class LibraryController : UIViewController

The LibraryController offers a way to quickly select and crop images or videos from the users Photo Library. Users can switch between regular albums, smart albums, iCloud albums, or albums imported directly from a DSLR camera. In addition, there is a separate section for selecting and deleting drafts.

Figure 1 Library controller

Screenshot

This controller is used inside the ContainerController and can be used on its own by initializing the container controller with only one mode .library.

For more information on modifying the cropping behavior of the library controller see its PreviewCropController.

The library controller can also be restricted to only display certain types of media. For example images only:

containerController.libraryController.fetchPredicate = NSPredicate(format: "mediaType == %d", PHAssetMediaType.image.rawValue)
containerController.libraryController.draftMediaTypes = [.image]

By default, the library controller pushes an EditController onto the navigation stack when the Next button is pressed. This can be disabled by setting showsEditControllerWhenDone to false. You will also need to implement the LibraryControllerDelegate in order to respond the libraryController(_:didFinishWithSession:withSegment:) delegate method.

Handling Controller Events

Restricting Media

  • Set this if you need to restrict the users Photo Library to a certain type of media.

    Only images for example:

    libraryController.fetchPredicate = NSPredicate(format: "mediaType == %d", PHAssetMediaType.image.rawValue)
    

    Default value: nil

    Declaration

    Swift

    public var fetchPredicate: NSPredicate?
  • Set this if you need to restrict the users Drafts to a certain type of media.

    Only images for example:

    libraryController.draftMediaTypes = [.image]
    

    Default value: [.image, .video]

    Declaration

    Swift

    public var draftMediaTypes: [MediaType] { get set }
  • When false, each video draft will appear as one draft.

    When true, each video draft will be displayed as individual segments. For example, if a video has 3 segments the draft will instead appear as 3 separate drafts.

    Default value: false

    Declaration

    Swift

    public var splitVideoDraftsIntoSegments: Bool { get set }

UI Components

  • The Cancel button in the top left corner of this controller.

    Declaration

    Swift

    @IBOutlet
    public private(set) var cancelButton: UIButton! { get }
  • The Next button in the top right corner of this controller.

    Declaration

    Swift

    @IBOutlet
    public private(set) var nextButton: UIButton! { get }
  • This activity indicator may briefly appear in place of the nextButton after it is pressed.

    Declaration

    Swift

    @IBOutlet
    public private(set) var activityIndicatorView: UIActivityIndicatorView! { get }

Cropping

  • This is the square preview controller at the top of this controller responsible for displaying and cropping media. Use this to customize cropping behavior.

    Declaration

    Swift

    public let previewCropController: PreviewCropController