Thursday, 22 August 2013

xcode - QLpreviewController generate thumb

xcode - QLpreviewController generate thumb

I want to generate thumbinal with this code:
It work on subview, but I want work on collection view
- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller
previewItemAtIndex:(NSInteger)index
{
NSString* completeFile = [[arrayDocumentLibary
objectAtIndex:index]nomeFileDocument];
NSString *documentWithoutExtension = [completeFile
stringByDeletingPathExtension];
NSString *documentOnlyExtension = [completeFile pathExtension];
NSString *path =
[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES)
objectAtIndex:0]stringByAppendingPathComponent:[NSString
stringWithFormat:@"%@.%@", documentWithoutExtension,
documentOnlyExtension]];
NSLog(@"%@index@%d", documentWithoutExtension, index);
return [NSURL fileURLWithPath:path];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return [arrayDocumentLibary count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
WVdACustomCell *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:cellIdentifier
forIndexPath:indexPath];
[[cell labelDescriptionDocument]setText:[[arrayDocumentLibary
objectAtIndex:indexPath.item]nomeFileDocument]];
[[cell imageThumbDocument]setImage:[WVdALibraryDocumentViewController
imageFromView:QLpreviewController.view]];
return cell;
}
+ (UIImage *)imageFromView:(UIView *)view {
CALayer *layer = view.layer;
UIGraphicsBeginImageContext([layer frame].size);
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outputImage;
}
But I don't get why not work! Help me please!

No comments:

Post a Comment