forked from SVGKit/SVGKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVCAllSpecImages.m
More file actions
101 lines (75 loc) · 3.19 KB
/
Copy pathVCAllSpecImages.m
File metadata and controls
101 lines (75 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#import "VCAllSpecImages.h"
#import "DetailViewController.h"
#import "SVGKSourceLocalFile.h"
@interface VCAllSpecImages ()
@property(nonatomic,retain) NSString* xcodeVirtualFolderPath;
@property(nonatomic,retain) NSMutableArray* svgFileNames;
@end
@implementation VCAllSpecImages
-(void)viewDidLoad
{
[super viewDidLoad];
if( self.svgFileNames == nil )
{
NSError *error = nil;
self.xcodeVirtualFolderPath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:self.pathInBundleToSVGSpecTestSuiteFolder];
NSArray *xcodeVirtualFolderSVGContents = [[NSFileManager defaultManager]
contentsOfDirectoryAtPath:[self.xcodeVirtualFolderPath stringByAppendingPathComponent:@"svg"] error:&error];
self.svgFileNames = [NSMutableArray arrayWithArray: xcodeVirtualFolderSVGContents];
}
}
-(NSArray*) sectionAtIndex:(NSInteger) index
{
return self.svgFileNames;
}
-(NSString*) filenameAtIndexPath:(NSIndexPath*) indexPath
{
NSArray* section = [self sectionAtIndex:indexPath.section];
NSString* item = [section objectAtIndex:indexPath.row];
return item;
}
#pragma mark - UICollectionView
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
NSString* filename = [self filenameAtIndexPath:indexPath];
UILabel* l = (UILabel*) [cell viewWithTag:1];
l.text = filename;
UIImageView* iv = (UIImageView*) [cell viewWithTag:2];
/** Xcode 3, 4, 5 and even version 6 -- all SUCK. "Groups", "Folders", and "Folder References" are all STILL broken by default
Spec adds hundreds of files, and Xcode deletes the folders. So must use folder-references. But Apple folder-references STILL break Apple's UIImage, so we have to specify manual path.
*/
NSString* fullPathImageFileName = [[self.xcodeVirtualFolderPath stringByAppendingPathComponent:@"png"] stringByAppendingPathComponent:filename];
UIImage* savedImage = [UIImage imageNamed: [fullPathImageFileName stringByDeletingPathExtension]];
if( savedImage != nil )
{
iv.image = savedImage;
}
else
iv.image = nil;
return cell;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self sectionAtIndex:section].count;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//SampleFileInfo* item = [self itemAtIndexPath:indexPath];
[self performSegueWithIdentifier:@"ViewSVG" sender:nil];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if( [segue.destinationViewController isKindOfClass:[DetailViewController class]])
{
DetailViewController* nextVC = (DetailViewController*) segue.destinationViewController;
NSString* filename = [self filenameAtIndexPath:[self.collectionView indexPathsForSelectedItems][0]];
nextVC.detailItem = [SVGKSourceLocalFile sourceFromFilename:[[self.xcodeVirtualFolderPath stringByAppendingPathComponent:@"svg"] stringByAppendingPathComponent:filename]];
}
}
@end