Created
June 8, 2014 15:51
-
-
Save almostintuitive/2d8d4020d64d72db6789 to your computer and use it in GitHub Desktop.
SVGView for iOS (using UIWebView)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SVGView.h | |
// Just call the loadSVG method with the SVG's NSData to display it with transparent background & scrollbars. | |
// | |
// github.com/itchingpixels. | |
// | |
#import <UIKit/UIKit.h> | |
@interface SVGView : UIWebView <UIWebViewDelegate> | |
- (void)loadSVG: (NSData*)svgData; | |
@end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SVGView., | |
// Just call the loadSVG method with the SVG's NSData to display it with transparent background & scrollbars. | |
// | |
// github.com/itchingpixels. | |
// | |
#import "SVGView.h" | |
@implementation SVGView | |
- (id)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) { | |
// Initialization code | |
} | |
return self; | |
} | |
- (void)loadSVG:(NSData*)svgData { | |
[self setBackgroundColor:[UIColor clearColor]]; | |
[self setOpaque:NO]; | |
[[self scrollView] setBounces: NO]; | |
self.delegate = self; | |
self.scrollView.scrollEnabled = NO; | |
[self loadData:svgData MIMEType:@"image/svg+xml" textEncodingName:0 baseURL:[[NSBundle mainBundle] bundleURL]]; | |
self.contentMode = UIViewContentModeScaleAspectFill; | |
[self setNeedsDisplay]; | |
} | |
- (void)webViewDidFinishLoad:(UIWebView *)webView { | |
CGSize contentSize = webView.scrollView.contentSize; | |
CGSize viewSize = webView.bounds.size; | |
float rw = viewSize.width / contentSize.width; | |
self.scrollView.minimumZoomScale = rw; | |
self.scrollView.maximumZoomScale = rw; | |
self.scrollView.zoomScale = 1; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment