/
ViewController.m
89 lines (73 loc) · 2.44 KB
/
ViewController.m
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
//
// ViewController.m
// pxSVG
//
// Created by Yury Popov on 12 мая.
// Copyright (c) 2015 PhoeniX. All rights reserved.
//
#import "ViewController.h"
#import <pxSVG/pxSVG.h>
@interface SVGCollectionCell : UICollectionViewCell <pxSVGViewDelegate>
@property (nonatomic) NSURL *SVGURL;
@property (weak) pxSVGView *svgView;
@end
@implementation SVGCollectionCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
pxSVGView *sv = [[pxSVGView alloc] initWithFrame:self.contentView.bounds];
sv.svgDelegate = self;
sv.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.contentView addSubview:_svgView=sv];
return self;
}
- (void)svgViewDidLoadImage:(pxSVGView *)svgView
{
NSLog(@"%@",self.SVGURL);
}
- (void)svgView:(pxSVGView *)svgLayer didFailedLoad:(NSError *)error
{
NSLog(@"%@ %@",self.SVGURL,error);
}
- (void)setSVGURL:(NSURL *)SVGURL
{
[self.svgView loadURL:SVGURL];
}
@end
@interface ViewController () <UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property NSArray *images;
@end
@implementation ViewController
- (instancetype)init
{
UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
layout.itemSize = (CGSize){160,160};
layout.sectionInset = UIEdgeInsetsZero;
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 0;
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
self = [super initWithCollectionViewLayout:layout];
self.images = [NSBundle URLsForResourcesWithExtension:@"svg" subdirectory:nil inBundleWithURL:[NSBundle mainBundle].bundleURL];
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.backgroundColor = [UIColor whiteColor];
[self.collectionView registerClass:[SVGCollectionCell class] forCellWithReuseIdentifier:@"cell"];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.images.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
SVGCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
[cell setSVGURL:self.images[indexPath.item]];
return cell;
}
@end