2017/3/3lesson

Mar 3, 2017

这几天打算使用Bundle管理SVG文件,给项目加上Theme功能。
SVG使用,使用的是SVGKit,使用Bundle需要稍微注意写法
比如使用寻找Path,

1
2
3
4
5
NSString *path = [[NSBundle mainBundle] pathForResource:@"AnimalTheme" ofType:@"bundle"];
NSString *ciweiFilePath = [path stringByAppendingPathComponent:@"刺猬.svg"];
SVGKImage *ciweiImage = [SVGKImage imageWithContentsOfFile:ciweiFilePath];
ciweiImage.size = CGSizeMake(30, 30);
ciweiImage.UIImage

1
2
3
4
5
6
SVGKImage im = [SVGKImage imageNamed:"myImage"];
CGSize originalSize = im.size; // this defaults to the SVG's internal size
float half = 1.0 / 2.0f;
im.size = CGSizeApplyAffineTransform( im.size, CGAffineTransformMakeScale( half, half ));
SVGKImageView* iv = [[SVGKFastImageView alloc] initWithSVGKImage: im];
[self.view addSubview: iv];
1
2
3
4
SVGKImage im = [SVGKImage imageNamed:"myImage"];
im.scale = 0.5f; // NB: this will BE REJECTED if your SVG is non-infinite;
SVGKImageView* iv = [[SVGKFastImageView alloc] initWithSVGKImage: im];
[self.view addSubview: iv];