• Stars
    star
    219
  • Rank 181,133 (Top 4 %)
  • Language
    Objective-C
  • License
    Other
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Highly customizable control used to select multiple assets (saved photos and videos) for use in your app.

TSAssetsPickerController

Β 

Highly customizable control used to select multiple assets (saved photos and videos) for use in your app.

It works similar to UIImagePickerController but allows to select multiple assets and this control is highly customizable. The control returns ALAsset objects which are easy to deal with. It also can filter assets by type and sizes.

Donate

If you like it... :)

Flattr this

Overview

TSAssetsPickerController is a controller you can use to select multiple assets (ALAsset objects).

Features

  • Browse all albums
  • Asset filtering (type, size)
  • Supports all orientations
  • Supports iOS6, iOS7
  • Supports iPhone, iPad
  • Allows to select multiple assets from one album
  • Customizable order of albums and assets,
  • Plenty of options to set.
  • Easy to apply in your project
  • Easy to customize

API Quickstart

There is few topics you should know about. Most important classes are TSAssetsPickerController, its delegate and dataSource, TSFilter with TSSizePredicate class, and UI classes which you can subclass to customize TSAssetsPickerController's UI.

TSAssetsPickerController uses TSAssetsPickerControllerDelegate and TSAssetsPickerControllerDataSource.


## TSAssetsPickerControllerDelegate Delegate has methods which your class have to implements. These methods are called when user finish picking assets, when user tapped cancel and when error occurs.

Method with error is called when user prohibits access to its Camera Roll.

Method which is called when user finished picking assets returns ALAssets objects. You can simply get picture or video from those ALAsset objects.

TSAssetsPickerControllerDataSource

Data source has plenty of methods that are used to configure TAssetsPickerController. Things which you can configure with data source are: number of items to select, filter (TSFilter described later), layout for assets view in selected orientation, look of activity indicators when fetching and finish picking assets, title of albums view, title of cancel button, title of select button, text of cell's label which is visible when no albums is available, reversed or normal order of albums/assets, determine if empty albums should be showed, and if should be, if picker should dimm title of cell which point on empty album.

Last but not least is method you should use to set subclasses for classes which you can customize.

Classes to subclass

Following table describes clases which you can subclass.

Class name Description
AlbumCell Base class of cel which is displayed of TSAlbumsViewController - cell with album name.
NoAlbumsCell Base class of cell which is displayed on TSAlbumsViewController when there is no albums to display.
AssetsCollectionViewLayout Base class of collection layout view used in TSAssetsViewController
AssetsCollectionView Base class of UICollectionView used in TSAssetsViewController.

TSFilter and TSSizePredicate

TSFilter is used by TSAssetsPickerControllerDataSource in method - (TSFilter *)filterOfAssetsPickerController:(TSAssetsPickerController *)picker. Instance of this class determines what sort of assets and whith which options assets should be filtered. It's very simple to use.

Instance may be created with filter (Photo, Video, All) and (optional) with one or more predicates.

Filter type is used to set if TSAssetsPickerController should shows only photos, videos or both of them.

Filter can also takes TSSizePredicate object which determines which assets of which sizes should be visible.


`TSSizePredicate` can match:
  • if assets is equal to size,
  • if assets is equal to one of few sizes,
  • if assets size is less (or equal) than declared size,
  • if assets size is greater (or equal) than declared size,

The most extensive designed initializer has ability to set logic gate. It is used to set more specific filters. You can set filter which accepts assets which are less than 512x512 AND greater than 256x256, or you can create filter which accepts assets less than 512x512 OR greater than 1024x1024. With simpler predicate you can set that picker should only accepts assets looks like screenshots by setting predicate which match array of sizes e.g. 640x1136, 1136x640, 640x960, 960x640, etc. There is plenty of posibilites to set filter.

TSSizePredicate accepts array of CGSize objects contained in NSValue objects. TSSizePredicate share macro TSSizeValue(width,height).

Examples

Creating TSAssetsPickerControllerInstnce.

    _picker = [TSAssetsPickerController new];
    _picker.delegate = self;
    _picker.dataSource = self;

To responds to actions performed by picker class must implements few picker delegate's methods.

	   #pragma mark - TSAssetsPickerControllerDelegate
	   - (void)assetsPickerControllerDidCancel:(TSAssetsPickerController *)picker {
	       [_picker dismissViewControllerAnimated:YES completion:nil];
	   }
	
	   - (void)assetsPickerController:(TSAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets {
	       [_picker dismissViewControllerAnimated:YES completion:nil];
	       [DummyAssetsImporter importAssets:assets]; // Here is some class which gets data from ALAssets objects pass into.
	   }
	
	   - (void)assetsPickerController:(TSAssetsPickerController *)picker failedWithError:(NSError *)error {
	       if (error) {
	           NSLog(@"Error occurs. Show dialog or something. Probably because user blocked access to Camera Roll.");
	       }
	   }

Two methods of picker's data source have to be also implemented.

    - (NSUInteger)numberOfItemsToSelectInAssetsPickerController:(TSAssetsPickerController *)picker {
        return 3;
    }

    - (TSFilter *)filterOfAssetsPickerController:(TSAssetsPickerController *)picker {
        TSSizePredicate *predicate = [TSSizePredicate matchSize:CGSizeMake(320, 480)];
        return [TSFilter filterWithType:FilterTypePhoto predicate:predicate];
    }

Setting layout for appropriate orientations:

	- (UICollectioftnViewLayout *)assetsPickerController:(TSAssetsPickerController *)picker needsLayoutForOrientation:(UIInterfaceOrientation)orientation {
	    AssetsCollectionViewLayout *layout = [AssetsCollectionViewLayout new];
	    if (UIInterfaceOrientationIsPortrait(orientation)) {
	        if (IS_IPHONE) {
	            [layout setItemSize:CGSizeMake(47, 47)];
	            [layout setItemInsets:UIEdgeInsetsMake(5.0f, 5.0f, 5.0f, 5.0f)];
	            [layout setInternItemSpacingY:4.0f];
	            [layout setNumberOfColumns:6];
	        } else {
	            [layout setItemSize:CGSizeMake(115, 115)];
	            [layout setItemInsets:UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f)];
	            [layout setInternItemSpacingY:10.0f];
	            [layout setNumberOfColumns:6];
	        }
	    } else {
	        if (IS_IPHONE) {
	            CGSize itemSize = CGSizeMake(48, 48);
	            if (IS_IPHONE_5) {
	                itemSize = CGSizeMake(45, 45);
	            }
	            [layout setItemSize:itemSize];
	            [layout setItemInsets:UIEdgeInsetsMake(5.0f, 5.0f, 5.0f, 5.0f)];
	            [layout setInternItemSpacingY:4.0f];
	            
	            NSUInteger columns = IS_IPHONE_5 ? 11 : 9;
	            [layout setNumberOfColumns:columns];
	        } else {
	            [layout setItemSize:CGSizeMake(115, 115)];
	            [layout setItemInsets:UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f)];
	            [layout setInternItemSpacingY:10.0f];
	            [layout setNumberOfColumns:8];
	        }
	    }
	    
	    return layout;
	}

UIActivityIndicatorView for both albums and assets views which is visible when picker is fetching data and when is finish picking.

	- (UIActivityIndicatorView *)assetsPickerController:(TSAssetsPickerController *)picker activityIndicatorViewForPlace:(ViewPlace)place {
	    UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
	    [indicatorView setColor:[UIColor redColor]];
	    [indicatorView setHidesWhenStopped:YES];
	    return indicatorView;
	}

Other optional methods of data source.

    - (NSString *)assetsPickerControllerTitleForAlbumsView:(TSAssetsPickerController *)picker {
	    return @"Albums";
    }
	
    - (NSString *)assetsPickerControllerTitleForCancelButtonInAlbumsView:(TSAssetsPickerController *)picker {
        return @"Cancel";
    }
	
    - (NSString *)assetsPickerControllerTitleForSelectButtonInAssetsView:(TSAssetsPickerController *)picker {
	    return @"Select";
    }
	
    - (NSString *)assetsPickerControllerTextForCellWhenNoAlbumsAvailable:(TSAssetsPickerController *)picker {
	    return @"Can't find any asset. Create some and back.";
    }
	
    - (BOOL)assetsPickerControllerShouldShowEmptyAlbums:(TSAssetsPickerController *)picker {
	    return YES;
    }
	
    - (BOOL)assetsPickerControllerShouldDimmCellsForEmptyAlbums:(TSAssetsPickerController *)picker {
        return NO;
    }
	
    - (BOOL)assetsPickerControllerShouldReverseAlbumsOrder:(TSAssetsPickerController *)picker {
	    return YES;
    }

Requirements

TSAssetsPickerController needs ARC and works only on iOS6 and iOS7.

Instalation

To install and use TSAssetsPickerController you have to add Classes directory to your project. If it's not from CocoaPods there should be three folders inside: Controllers, Customizable Classes and API Classes. After that you need import TSAssetsPickerController. It imports all needed to work classes.

#import "TSAssetsPickerController.h"

via CocoaPods

TSAssetsPickerControlller is also available on CocoaPods.

pod 'TSAssetsPickerController'

Changelog

1.2 (02.03.2014)
  • UICollectionFlowLayout replaced with UICollectionViewLayout. Now setting layout is available via data source of TSAssetsPickerController.
  • Added customizable activity indicators during fetching albums and assets and when picker is finish picking.
  • Fixed wrong height of UICollectionView in TSAssetsViewController on iOS 6.
  • AssetCell's thumbnailImageView and movieMarkImageView now are updating layout correctly.
  • Improved performance during scrolling and loading 1000+ assets.
1.1 (27.02.2014)
  • Added TSFilter to filter assets before showing it to the user.
  • Properties of TSAssetsPickerController have been moved to data source.
  • Fixed reversing albums list.
1.0.2 (23.02.2014)
  • Added Podspec of TSAssetsPickerController. Now available on CocoaPods
1.0.1 (23.02.2014)
  • Added rotation support
1.0 (22.02.2014)
  • Implemented basic functionality
  • Added to github

License

TSAssetsPickerController is available under the Apache 2.0 license.

Copyright Β© 2014 Tomasz Szulc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

Swifternalization

Localize iOS apps in a smarter way using JSON files. Swift framework.
Swift
579
star
2

fireworks

Fireworks for UIView
Swift
340
star
3

TSValidatedTextField

Simple and ready to use subclass of UITextField which uses NSRegularExpression to allows you to validate text in the text field with pattern you set.
Objective-C
311
star
4

NetworkLayerExample

Demo project for the article: http://szulctomasz.com/how-do-I-build-a-network-layer/ (Swift 3)
Swift
255
star
5

TSFileCache

Generic class that allows you to cache files on device's disk. Need to cache images or other files? Check this. Easy to subclass and reuse.
Objective-C
98
star
6

TSActivityIndicatorView

Very simple view class that looks like an UIActivityIndicatorView but is fully customizable. It's great for you if you want to add indicator view to you game or app and it should be customized.
Objective-C
70
star
7

Quotes

Swift app containing iOS 8/9 features and things mentioned on WWDC 2015
Swift
25
star
8

2048

2048 written in Swift in 10 hours and shipped to the App Store
Swift
23
star
9

demo-xcconfig

Demo that shows how to use xcconfig files
Swift
23
star
10

citybike-app

City Bike - Find Free Bike - Swift - Open Source app
Swift
16
star
11

undo-manager-practice

Simple app that presents how to use NSUndoManager to undo and redo user's actions
Swift
12
star
12

cloudkit-demo-goatstagram

Very simple demo that shows how to check account status, fetch and save subscriptions and fetch objects from the backend
Swift
12
star
13

TSTextMapper

It maps text inside UILabel and allows you to detect tapped words
Swift
11
star
14

python-fav-memes-rest-api

RESTful Web Service written in Python/Flask for storing and getting your favourite memes
Python
7
star
15

eslpod-downloader

Python script which downloads available episodes of http://eslpod.com podcast. ~27GB
Python
5
star
16

TSCircleView

A subclass of MKCircleView which supports scaling and animating.
Objective-C
5
star
17

UnusedStrings

Helps Cocoa applications localization by detecting unused keys in '.strings' files.
Shell
4
star
18

Endpoints

Super simple library to describe endpoints for your network layer
Swift
3
star
19

ExpandingViewTransition-Demo

Example of how to create custom view controllers transition
Swift
3
star
20

Response

Tiny class for carrying a network response. You might want to use it with tomkowz/Endpoints
Swift
3
star
21

szulctomasz.com

Personal blog. #ios #swift #objective-c #programming
CSS
2
star
22

MemesBrowser-Network-Layer-Demo

Demo of a new Network Layer architecture I learned recently.
Swift
1
star
23

imessage-memes-extension

Simple extension for iMessage that provides my favourite memes from my VPS
Swift
1
star
24

Nothing-App

"To Do" iOS Swift App created for the Master's Thesis
Swift
1
star
25

twiliovoice

Python
1
star
26

transitioning-button-demo

For my blog. Button like control with nice transitions
Swift
1
star
27

arduino-eeprom-example

Example of using EEPROM
Makefile
1
star