Permalink
Browse files

Two extra convenience methods.

[ UIImage imageWithPDFNamed: atHeight: ]
[ UIImage originalSizeImageWithPDFNamed: ]
  • Loading branch information...
1 parent 5e10299 commit d521250a43906b89d1d220327b605652db6b3974 @mindbrix committed Dec 27, 2011
Showing with 35 additions and 3 deletions.
  1. +12 −2 Classes/UIImage_PDF_exampleViewController.m
  2. +2 −0 UIImage+PDF/UIImage+PDF.h
  3. +21 −1 UIImage+PDF/UIImage+PDF.m
@@ -35,6 +35,13 @@ - (void)loadView {
- (void)viewDidLoad {
[super viewDidLoad];
+
+ UIImageView *imageView = [[ UIImageView alloc ] initWithImage:[ UIImage originalSizeImageWithPDFNamed:@"YingYang.pdf" ]];
+ imageView.center = self.view.center;
+ [ self.view addSubview:imageView ];
+ [ imageView release ];
+
+
/* Draw a growing line of buttons to demonstate the scaling
*/
float kInset = 4;
@@ -57,12 +64,15 @@ - (void)viewDidLoad {
/* Set the button image from the PDF asset.
*/
- [ yingYangButton setImage:[ UIImage imageWithPDFNamed:@"YingYang.pdf" atSize:imageSize ] forState:UIControlStateNormal ];
+ [ yingYangButton setImage:[ UIImage imageWithPDFNamed:@"YingYang.pdf" atSize:imageSize ] forState:UIControlStateNormal ];
+
+ //[ yingYangButton setImage:[ UIImage imageWithPDFNamed:@"YingYang.pdf" atHeight:imageSize.height ] forState:UIControlStateNormal ];
+ //[ yingYangButton setImage:[ UIImage imageWithPDFNamed:@"YingYang.pdf" atWidth:imageSize.width ] forState:UIControlStateNormal ];
[ self.view addSubview:yingYangButton ];
buttonY += buttonWidth + kSpacing;
- }
+ }
}
@@ -14,5 +14,7 @@
+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atSize:(CGSize)size;
+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atWidth:(CGFloat)width;
++(UIImage *) imageWithPDFNamed:(NSString *)resourceName atHeight:(CGFloat)height;
++(UIImage *) originalSizeImageWithPDFNamed:(NSString *)resourceName;
@end
View
@@ -10,6 +10,7 @@
@implementation UIImage( PDF )
+
+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atSize:(CGSize)size
{
PDFView *pdfView = [[[ PDFView alloc ] initWithFrame:CGRectMake( 0, 0, size.width, size.height ) ] autorelease ];
@@ -20,7 +21,6 @@ +(UIImage *) imageWithPDFNamed:(NSString *)resourceName atSize:(CGSize)size
}
-
+(UIImage *) imageWithPDFNamed:(NSString *)resourceName atWidth:(CGFloat)width
{
CGRect mediaRect = [ PDFView mediaRect:resourceName ];
@@ -31,4 +31,24 @@ +(UIImage *) imageWithPDFNamed:(NSString *)resourceName atWidth:(CGFloat)width
return [ UIImage imageWithPDFNamed:resourceName atSize:size ];
}
+
++(UIImage *) imageWithPDFNamed:(NSString *)resourceName atHeight:(CGFloat)height
+{
+ CGRect mediaRect = [ PDFView mediaRect:resourceName ];
+ CGFloat aspectRatio = mediaRect.size.width / mediaRect.size.height;
+
+ CGSize size = CGSizeMake( ceilf( height * aspectRatio ), height );
+
+ return [ UIImage imageWithPDFNamed:resourceName atSize:size ];
+}
+
+
++(UIImage *) originalSizeImageWithPDFNamed:(NSString *)resourceName
+{
+ CGRect mediaRect = [ PDFView mediaRect:resourceName ];
+
+ return [ UIImage imageWithPDFNamed:resourceName atSize:mediaRect.size ];
+}
+
+
@end

0 comments on commit d521250

Please sign in to comment.