No description or website provided.
Objective-C Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
DragDropImageView
Example
.gitignore
.travis.yml
DragDropImageView.gif
DragDropImageView.podspec
LICENSE
README.md

README.md

DragDropImageView

Version License Platform

Exemple

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

SDK 10.7 (Mavericks) minimum

Installation

DragDropImageView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DragDropImageView"

How To

DragDropImageView is a custom NSImageView which can accept Drag and Drop Operation. To use it just make inherit an NSImageView on your nib and implement DragDropImageViewDelegate protocol in your controller.

Delegate Protocol Exemple

Implement DragDropImageViewDelegate methods like this in your controller.

-(NSImage *)dragDropImageView:(DragDropImageView *)dragDropImageView imageForStatus:(DragDropStatus)status{
    NSImage * image = s_empty;

    id dataToTest = nil;
    if(dragDropImageView == _dragDropSingle){
        dataToTest = self.pathSingleFile;
    } else {
        dataToTest = self.pathMultiFile;
    }
    if(status == DragDropValidType){
        image = s_validType;
    } else if(status==DragDropInvalidType) {
        image = s_invalidType;
    } else if(dataToTest){
        image =s_accepted;
    }
    return image;
}



-(BOOL)dragDropImageView:(DragDropImageView *)dragDropImageView areValidFiles:(NSArray *)files{
    __block BOOL valid = NO;
    [files enumerateObjectsUsingBlock:^(id object, NSUInteger idx, BOOL *stop) {
        CFStringRef fileExtension = (__bridge CFStringRef)[object pathExtension];
        CFStringRef fileUTI       = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);

        valid = UTTypeConformsTo(fileUTI, kUTTypeAudio);
        *stop = !valid;

    }];
    return valid;
}
-(void)dragDropImageView:(DragDropImageView *)dragDropImageView provideFiles:(NSArray *)files{
    if(dragDropImageView == _dragDropSingle){
        self.pathSingleFile = files[0];
    } else {
        self.pathMultiFile = files;
    }
}

Author

Léo Derbois, contact@leoderbois.com, www.leoderbois.com

License

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