DragDropImageView 1.0.1

DragDropImageView 1.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Nov 2015

Maintained by Léo Derbois.


Downloads

Total501
Week0
Month0

Installs

Apps17
Pod Tries2
powered by Segment

GitHub

Stars6
Watchers1
Forks0
Issues0
Contributors1
Pull Requests0

Code

Files2
LOCLines of Code 93


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

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, [email protected], www.leoderbois.com

License

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