Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions Classes/ELCImagePicker/ELCAssetCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,63 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
return self;
}

- (UIImage *)imageForAsset:(ALAsset *)asset
{
UIImage *image;

image = [UIImage imageWithCGImage:asset.thumbnail];
if([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
UIImage *typeImage;
UIView *view;
UIView *typeView;
NSNumber *duration;
UILabel *durationLabel;
NSInteger nbSeconds;
NSInteger nbMinutes;
NSInteger nbHours;
CAGradientLayer *gradientLayer;
UIImageView *imageView;

imageView = [[UIImageView alloc] initWithImage:image];
typeImage = [UIImage imageNamed:@"videoType.png"];

duration = [asset valueForProperty:ALAssetPropertyDuration];
durationLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, image.size.height - 29, image.size.width - 10, 20)];
durationLabel.textColor = [UIColor whiteColor];
durationLabel.textAlignment = NSTextAlignmentRight;
durationLabel.font = [durationLabel.font fontWithSize:24];
nbHours = duration.doubleValue/60/60;
nbMinutes = duration.doubleValue/60 - nbHours*60;
nbSeconds = duration.doubleValue - nbMinutes*60 - nbHours*60*60;
if(nbHours == 0) {
durationLabel.text = [NSString stringWithFormat:@"%02d:%02d", (int)nbMinutes, (int)nbSeconds];
}
else {
durationLabel.text = [NSString stringWithFormat:@"%d:%02d:%02d", (int)nbHours, (int)nbMinutes, (int)nbSeconds];
}

gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = @[(id)[UIColor colorWithWhite:0 alpha:0].CGColor, (id)[UIColor colorWithWhite:0 alpha:0.7].CGColor];
gradientLayer.frame = CGRectMake(0, image.size.height - 34, image.size.width , 34);
[imageView.layer addSublayer:gradientLayer];

view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
typeView = [[UIImageView alloc] initWithImage:typeImage];
[view addSubview:imageView];
[view addSubview:typeView];
[view addSubview:durationLabel];
typeView.contentMode = UIViewContentModeCenter;
typeView.frame = CGRectMake(10, view.bounds.size.height - 31, 28, 28);

UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}

return image;
}

- (void)setAssets:(NSArray *)assets
{
self.rowAssets = assets;
Expand All @@ -57,9 +114,9 @@ - (void)setAssets:(NSArray *)assets

if (i < [_imageViewArray count]) {
UIImageView *imageView = [_imageViewArray objectAtIndex:i];
imageView.image = [UIImage imageWithCGImage:asset.asset.thumbnail];
imageView.image = [self imageForAsset:asset.asset];
} else {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:asset.asset.thumbnail]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[self imageForAsset:asset.asset]];
[_imageViewArray addObject:imageView];
}

Expand Down
Binary file added Classes/ELCImagePicker/Resources/videoType.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion ELCImagePickerDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
2899E5220DE3E06400AC0155 /* ELCImagePickerDemoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2899E5210DE3E06400AC0155 /* ELCImagePickerDemoViewController.xib */; };
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; };
28D7ACF80DDB3853001CB0EB /* ELCImagePickerDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D7ACF70DDB3853001CB0EB /* ELCImagePickerDemoViewController.m */; };
4A3E18481A41FF7000AE971F /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A3E18471A41FF7000AE971F /* QuartzCore.framework */; };
4A3E184B1A4201E900AE971F /* videoType.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A3E18491A4201E900AE971F /* videoType.png */; };
4A3E184C1A4201E900AE971F /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4A3E184A1A4201E900AE971F /* [email protected] */; };
4AAFDA62194840F20020FCC4 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4AAFDA61194840F20020FCC4 /* MobileCoreServices.framework */; };
83C6BC9714476B280064D71D /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 83C6BC9514476B280064D71D /* [email protected] */; };
83C6BC9814476B280064D71D /* elc-ios-icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 83C6BC9614476B280064D71D /* elc-ios-icon.png */; };
Expand Down Expand Up @@ -60,6 +63,10 @@
28D7ACF70DDB3853001CB0EB /* ELCImagePickerDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ELCImagePickerDemoViewController.m; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* ELCImagePickerDemo_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ELCImagePickerDemo_Prefix.pch; sourceTree = "<group>"; };
4A3E18461A41FF1500AE971F /* ELCImagePickerHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ELCImagePickerHeader.h; sourceTree = "<group>"; };
4A3E18471A41FF7000AE971F /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
4A3E18491A4201E900AE971F /* videoType.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = videoType.png; path = Classes/ELCImagePicker/Resources/videoType.png; sourceTree = "<group>"; };
4A3E184A1A4201E900AE971F /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "[email protected]"; path = "Classes/ELCImagePicker/Resources/[email protected]"; sourceTree = "<group>"; };
4AAFDA61194840F20020FCC4 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
5FAEB088190A3FA9002D73C4 /* ELCImagePickerHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ELCImagePickerHeader.h; sourceTree = "<group>"; };
83C6BC9514476B280064D71D /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
Expand All @@ -78,6 +85,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4A3E18481A41FF7000AE971F /* QuartzCore.framework in Frameworks */,
4AAFDA62194840F20020FCC4 /* MobileCoreServices.framework in Frameworks */,
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */,
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
Expand Down Expand Up @@ -148,6 +156,8 @@
1A4C631317380272001E0978 /* [email protected] */,
83C6BC9514476B280064D71D /* [email protected] */,
83C6BC9614476B280064D71D /* elc-ios-icon.png */,
4A3E18491A4201E900AE971F /* videoType.png */,
4A3E184A1A4201E900AE971F /* [email protected] */,
28AD733E0D9D9553002E5188 /* MainWindow.xib */,
8D1107310486CEB800E47090 /* ELCImagePickerDemo-Info.plist */,
);
Expand All @@ -157,6 +167,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
4A3E18471A41FF7000AE971F /* QuartzCore.framework */,
4AAFDA61194840F20020FCC4 /* MobileCoreServices.framework */,
E29A5E3B1239C42A008BB149 /* AssetsLibrary.framework */,
288765A40DF7441C002DB57D /* CoreGraphics.framework */,
Expand All @@ -181,7 +192,7 @@
1A2C0FFB17026CF0004FAFA0 /* ELCAssetTablePicker.m */,
1A2C100217026CF0004FAFA0 /* ELCImagePickerController.h */,
1A2C0FFC17026CF0004FAFA0 /* ELCImagePickerController.m */,
5FAEB088190A3FA9002D73C4 /* ELCImagePickerHeader.h */,
4A3E18461A41FF1500AE971F /* ELCImagePickerHeader.h */,
F1DF783E196FA475003524A2 /* ELCConsole.h */,
F1DF783F196FA475003524A2 /* ELCConsole.m */,
F1DF7840196FA475003524A2 /* ELCOverlayImageView.h */,
Expand Down Expand Up @@ -243,11 +254,13 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4A3E184C1A4201E900AE971F /* [email protected] in Resources */,
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */,
2899E5220DE3E06400AC0155 /* ELCImagePickerDemoViewController.xib in Resources */,
83C6BC9714476B280064D71D /* [email protected] in Resources */,
83C6BC9814476B280064D71D /* elc-ios-icon.png in Resources */,
230644BC15F8C0BB007679C7 /* MainWindow-iPad.xib in Resources */,
4A3E184B1A4201E900AE971F /* videoType.png in Resources */,
0B67B05B17E0ED1F002CC2C5 /* [email protected] in Resources */,
1A4C631417380272001E0978 /* Overlay.png in Resources */,
1A4C631517380272001E0978 /* [email protected] in Resources */,
Expand Down