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
4 changes: 4 additions & 0 deletions Classes/JAMSVGImage/SVG Image/JAMSVGImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
/** Scale at which the SVG image will be drawn. Default is 1.0. */
@property (nonatomic) CGFloat scale;

/** Allows setting the caching behavior. Defaults to true. */
+ (BOOL)isCachingEnabled;
+ (void)setIsCachingEnabled:(BOOL)isCachingEnabled;

/** Returns a CGImageRef or UIImage of the SVG image at the current scale. */
- (CGImageRef)CGImage;
- (UIImage *)image;
Expand Down
28 changes: 23 additions & 5 deletions Classes/JAMSVGImage/SVG Image/JAMSVGImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ @interface JAMSVGImage ()

@implementation JAMSVGImage

static BOOL _isCachingEnabled = YES; // caching is enabled by default
static NSCache *imageCache = nil;

#pragma mark - NSCoding Methods
Expand Down Expand Up @@ -70,13 +71,19 @@ + (JAMSVGImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle
if (!fileName) {
fileName = [bundle pathForResource:name ofType:@"svgz"];
}

JAMSVGImage *image = [imageCache objectForKey:fileName];
if (!image) {

JAMSVGImage *image;

if (_isCachingEnabled) {
image = [imageCache objectForKey:fileName];
if (!image) {
image = [JAMSVGImage imageWithContentsOfFile:fileName];
[imageCache setObject:image forKey:fileName];
}
} else {
image = [JAMSVGImage imageWithContentsOfFile:fileName];
[imageCache setObject:image forKey:fileName];
}

return image;
}

Expand Down Expand Up @@ -189,4 +196,15 @@ - (UIImage *)imageAtSize:(CGSize)size;
return image;
}

+ (BOOL)isCachingEnabled {
return _isCachingEnabled;
}

+ (void)setIsCachingEnabled:(BOOL)isCachingEnabled {
if (imageCache && !isCachingEnabled) {
[imageCache removeAllObjects];
}
_isCachingEnabled = isCachingEnabled;
}

@end
24 changes: 24 additions & 0 deletions Classes/JAMSVGImage/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.6</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
25 changes: 25 additions & 0 deletions Classes/JAMSVGImage/Supporting Files/JAMSVGImage-Umbrella.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// JAMSVGImage-Umbrella.h
// JAMSVGImage
//
// Created by Cihat Gündüz on 11.01.17.
// Copyright © 2017 Jeff Menter. All rights reserved.
//

#import <Foundation/Foundation.h>

//! Project version number for JAMSVGImage iOS.
FOUNDATION_EXPORT double JAMSVGImage_VersionNumber;

//! Project version string for JAMSVGImage iOS.
FOUNDATION_EXPORT const unsigned char JAMSVGImage_VersionString[];

#import <JAMSVGImage/JAMSVGImage.h>
#import <JAMSVGImage/UIImage+SVG.h>
#import <JAMSVGImage/JAMSVGImageView.h>
#import <JAMSVGImage/JAMSVGButton.h>
#import <JAMSVGImage/JAMStyledBezierPath.h>
#import <JAMSVGImage/JAMSVGParser.h>
#import <JAMSVGImage/JAMStyledBezierPathFactory.h>
#import <JAMSVGImage/JAMSVGGradientParts.h>
#import <JAMSVGImage/JAMSVGUtilities.h>
6 changes: 6 additions & 0 deletions Classes/JAMSVGImage/Supporting Files/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
framework module JAMSVGImage {
umbrella header "JAMSVGImage-Umbrella.h"

export *
module * { export * }
}
369 changes: 369 additions & 0 deletions JAMSVGImage.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8225C2FE1E26391C00229F51"
BuildableName = "JAMSVGImage.framework"
BlueprintName = "JAMSVGImage-iOS"
ReferencedContainer = "container:JAMSVGImage.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8225C2FE1E26391C00229F51"
BuildableName = "JAMSVGImage.framework"
BlueprintName = "JAMSVGImage-iOS"
ReferencedContainer = "container:JAMSVGImage.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8225C2FE1E26391C00229F51"
BuildableName = "JAMSVGImage.framework"
BlueprintName = "JAMSVGImage-iOS"
ReferencedContainer = "container:JAMSVGImage.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8225C3101E26392800229F51"
BuildableName = "JAMSVGImage.framework"
BlueprintName = "JAMSVGImage-tvOS"
ReferencedContainer = "container:JAMSVGImage.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8225C3101E26392800229F51"
BuildableName = "JAMSVGImage.framework"
BlueprintName = "JAMSVGImage-tvOS"
ReferencedContainer = "container:JAMSVGImage.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8225C3101E26392800229F51"
BuildableName = "JAMSVGImage.framework"
BlueprintName = "JAMSVGImage-tvOS"
ReferencedContainer = "container:JAMSVGImage.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,40 @@ __Convenience__: there's no need to generate @2x and @3x versions of your art as

__File Size__: SVG and SVGZ (gzipped SVG) are typically a fraction of the file size of a set of PNG or JPG art assets.

Installation
-----

If you are using Swift in your project, the recommended way of installing this library is via [Carthage](https://github.com/Carthage/Carthage). [Cocoapods](https://github.com/CocoaPods/CocoaPods) is supported, too. You can of course also just include this framework manually into your project by downloading it or by using git submodules.

### Carthage

Add the following line to your `Cartfile`:

``` Swift
github "jmenter/JAMSVGImage" ~> 1.7
```

Now run `carthage update`. Then drag & drop the JAMSVGImage.framework in the Carthage/Build folder to your project. Now you can `import JAMSVGImage` in each class you want to use its features. Refer to the [Carthage README](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) for detailed / updated instructions.

### CocoaPods

Add the line `pod 'JAMSVGImage'` to your target in your `Podfile` and make sure to include `use_frameworks!`
at the top. The result might look similar to this:

``` Ruby
platform :ios, '8.0'
use_frameworks!

target 'MyAppTarget' do
pod 'JAMSVGImage', '~> 1.7'
end
```

Now close your project and run `pod install` from the command line. Then open the `.xcworkspace` from within your project folder.
Build your project once (with `Cmd+B`) to update the frameworks known to Xcode. Now you can `import JAMSVGImage` in each class you want to use its features.
Refer to [CocoaPods.org](https://cocoapods.org) for detailed / updates instructions.


Usage
-----

Expand All @@ -42,7 +76,7 @@ Third, you can create a JAMSVGImage instance and use the drawInCurrentContext me
You can also call [tiger image] or .CGImage to get a raster UIImage or CGImageRef and use that anywhere you would use a UIImage or CGImageRef. You can set the scale before getting the image if you need it bigger or smaller, or you can pass in a rect to have the SVG rendered in that rect at the proper scale for your device (whether it's a @1x, @2x, or @3x screen):

[self.button setBackgroundImage:[[JAMSVGImage imageNamed:@"fancyButton"] imageAtSize:self.button.bounds.size] forState:UIControlStateNormal];

Last, there is a JAMSVGButton subclass of UIButton that allows setting the four button states to SVG files via Interface Builder.

![JAMSVGButton Example](https://raw.githubusercontent.com/jmenter/JAMSVGImage/develop/svgButtonExample.png)
Expand Down