diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f8ad7bd --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +BasedOnStyle: LLVM + +DerivePointerAlignment: false +PointerAlignment: Right +ObjCSpaceAfterProperty: true +UseTab: Always +IndentWidth: 4 +TabWidth: 4 +ColumnLimit: 0 +BreakBeforeBraces: Allman +IndentCaseLabels: true +SpacesInContainerLiterals: true diff --git a/README.md b/README.md index 88ef0be..cbd8ede 100644 --- a/README.md +++ b/README.md @@ -27,47 +27,47 @@ Add the following line to import the required classes. Syntax is similar to creating a `UIImage`: - PDFImage* image = [PDFImage imageNamed:@"email"]; + PDFImage *image = [PDFImage imageNamed:@"email"]; This will load the `email.pdf` file from the main bundle. To show the `PDFImage` on the screen: - PDFImage* image = [PDFImage imageNamed:@"email"]; + PDFImage *image = [PDFImage imageNamed:@"email"]; - PDFImageView* imageView = [[PDFImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; - [imageView setImage:image]; + PDFImageView *imageView = [[PDFImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + imageView.image = image; [view addSubview:imageView]; The `PDFImageView` will automatically make sure a pixel perfect version of the loaded PDF is drawn to screen, even if the view is resized or animated. A `UIImage` can be generated as so: - PDFImage* image = [PDFImage imageNamed:@"email"]; + PDFImage *image = [PDFImage imageNamed:@"email"]; - PDFImageOptions* options = [PDFImageOptions optionsWithSize:CGSizeMake(50, 50)]; + PDFImageOptions *options = [PDFImageOptions optionsWithSize:CGSizeMake(50, 50)]; - UIImage* result = [image imageWithOptions:options]; + UIImage *result = [image imageWithOptions:options]; By default, the resulting `UIImage` is drawn scale to fill. If required, the options can use any `UIViewContentMode` to adjust how the result is drawn. - PDFImage* image = [PDFImage imageNamed:@"email"]; + PDFImage *image = [PDFImage imageNamed:@"email"]; - PDFImageOptions* options = [PDFImageOptions optionsWithSize:CGSizeMake(50, 50)]; - [options setContentMode:UIViewContentModeScaleAspectFit]; + PDFImageOptions *options = [PDFImageOptions optionsWithSize:CGSizeMake(50, 50)]; + options.contentMode = UIViewContentModeScaleAspectFit; - UIImage* result = [image imageWithOptions:options]; + UIImage *result = [image imageWithOptions:options]; A tintColor can also be specified to change the entire color, useful for reusing the same graphics in different colors. - PDFImageOptions* options = ...; - [options setTintColor:[UIColor redColor]]; + PDFImageOptions *options = ...; + options.tintColor = [UIColor redColor]; // or - PDFImageView* imageView = ...; - [imageView setTintColor:[UIColor redColor]]; + PDFImageView *imageView = ...; + imageView.tintColor = [UIColor redColor]; See the included headers of the [`PDFImage.framework`](../../releases/latest) for the full API interface. diff --git a/Xcode/PDFImage/PDFBarButtonItem.h b/Xcode/PDFImage/PDFBarButtonItem.h index 507c735..e8f4386 100644 --- a/Xcode/PDFImage/PDFBarButtonItem.h +++ b/Xcode/PDFImage/PDFBarButtonItem.h @@ -33,6 +33,6 @@ // Scales the image down proportionally to fit into a target size of 28x28 // for best results, the PDFImage should be as close to the target size as possible -- (instancetype) initWithImage:(PDFImage*) image style:(UIBarButtonItemStyle) style target:(id) target action:(SEL) action; +- (instancetype)initWithImage:(PDFImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action; @end diff --git a/Xcode/PDFImage/PDFBarButtonItem.m b/Xcode/PDFImage/PDFBarButtonItem.m index 6657b3d..571e71f 100644 --- a/Xcode/PDFImage/PDFBarButtonItem.m +++ b/Xcode/PDFImage/PDFBarButtonItem.m @@ -34,16 +34,16 @@ @interface PDFBarButtonItem () -@property (nonatomic, readonly) PDFImage* originalImage; +@property (nonatomic, readonly) PDFImage *originalImage; @property (nonatomic, readonly) CGSize targetSize; @end @implementation PDFBarButtonItem -+ (void) initialize ++ (void)initialize { - if(self == [PDFBarButtonItem class]) + if (self == [PDFBarButtonItem class]) { isiOS7OrGreater = ([UIDevice currentDevice].systemVersion.integerValue >= 7); } @@ -51,56 +51,55 @@ + (void) initialize #pragma mark - -- (instancetype) initWithImage:(PDFImage*) image style:(UIBarButtonItemStyle) style target:(id) target action:(SEL) action +- (instancetype)initWithImage:(PDFImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action { return [self initWithImage:image style:style target:target action:action targetSize:CGSizeMake(28, 28)]; } -- (instancetype) initWithImage:(PDFImage*) image style:(UIBarButtonItemStyle) style target:(id) target action:(SEL) action targetSize:(CGSize) targetSize +- (instancetype)initWithImage:(PDFImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action targetSize:(CGSize)targetSize { self = [super initWithImage:nil style:style target:target action:action]; - - if(self != nil) + + if (self != nil) { _originalImage = image; _targetSize = targetSize; - + [self updateBarButtonImage]; } - + return self; } #pragma mark - #pragma mark Super -- (void) setTintColor:(UIColor *)tintColor +- (void)setTintColor:(UIColor *)tintColor { [super setTintColor:tintColor]; - + [self updateBarButtonImage]; } #pragma mark - #pragma mark Private -- (void) updateBarButtonImage +- (void)updateBarButtonImage { - PDFImage* originalImage = self.originalImage; + PDFImage *originalImage = self.originalImage; const CGSize imageSize = [[PDFImageOptions optionsWithSize:self.targetSize] wholeProportionalFitForContentSize:originalImage.size]; - + // The color of the image, // on iOS6 we colorize it only if we're using a bordered style (not plain), // on iOS7+ white is used, as the UIBarButtonItem tint color will colorize our image anyway - UIColor* tintColor = self.tintColor; - if(tintColor == nil || (self.style != UIBarButtonItemStylePlain && !isiOS7OrGreater) || isiOS7OrGreater) + UIColor *tintColor = self.tintColor; + if (tintColor == nil || (self.style != UIBarButtonItemStylePlain && !isiOS7OrGreater) || isiOS7OrGreater) tintColor = [UIColor whiteColor]; - - PDFImageOptions* options = [PDFImageOptions optionsWithSize:imageSize]; - [options setTintColor:tintColor]; - - UIImage* image = [originalImage imageWithOptions:options]; - [self setImage:image]; + + PDFImageOptions *options = [PDFImageOptions optionsWithSize:imageSize]; + options.tintColor = tintColor; + + self.image = [originalImage imageWithOptions:options]; } @end diff --git a/Xcode/PDFImage/PDFImage.h b/Xcode/PDFImage/PDFImage.h index f97aab8..f6204cf 100644 --- a/Xcode/PDFImage/PDFImage.h +++ b/Xcode/PDFImage/PDFImage.h @@ -43,22 +43,22 @@ // may result in a new instance and not the version in NSCache, the same applies to imageWithOptions: @interface PDFImage : NSObject -@property (nonatomic, readonly) CGSize size; // original page size +@property (nonatomic, readonly) CGSize size; // original page size -+ (instancetype) imageNamed:(NSString*) name; // from the main bundle, the .pdf extension can be omitted, - // this and +imageNamed:inBundle: are the only methods that will NSCache PDFImages, as bundles are read-only ++ (instancetype)imageNamed:(NSString *)name; // from the main bundle, the .pdf extension can be omitted, + // this and +imageNamed:inBundle: are the only methods that will NSCache PDFImages, as bundles are read-only -+ (instancetype) imageNamed:(NSString*) name inBundle:(NSBundle*) bundle; ++ (instancetype)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle; -+ (instancetype) imageWithContentsOfFile:(NSString*) path; -+ (instancetype) imageWithData:(NSData*) data; ++ (instancetype)imageWithContentsOfFile:(NSString *)path; ++ (instancetype)imageWithData:(NSData *)data; -- (instancetype) initWithContentsOfFile:(NSString*) path; -- (instancetype) initWithData:(NSData*) data; +- (instancetype)initWithContentsOfFile:(NSString *)path; +- (instancetype)initWithData:(NSData *)data; -- (instancetype) initWithDocument:(CGPDFDocumentRef) document; +- (instancetype)initWithDocument:(CGPDFDocumentRef)document; -- (UIImage*) imageWithOptions:(PDFImageOptions*) options; // will NSCache the image if the same options are used again -- (void) drawInRect:(CGRect) rect; +- (UIImage *)imageWithOptions:(PDFImageOptions *)options; // will NSCache the image if the same options are used again +- (void)drawInRect:(CGRect)rect; @end diff --git a/Xcode/PDFImage/PDFImage.m b/Xcode/PDFImage/PDFImage.m index 8432942..3e8dcf2 100644 --- a/Xcode/PDFImage/PDFImage.m +++ b/Xcode/PDFImage/PDFImage.m @@ -29,11 +29,11 @@ #import "PDFImageOptions.h" -static NSCache* sharedPDFImageCache = nil; +static NSCache *sharedPDFImageCache = nil; @interface PDFImage () { - NSCache* _imageCache; + NSCache *_imageCache; dispatch_once_t _imageCacheOnceToken; } @@ -44,190 +44,194 @@ @interface PDFImage () @implementation PDFImage -+ (instancetype) imageNamed:(NSString*) name ++ (instancetype)imageNamed:(NSString *)name { return [self imageNamed:name inBundle:[NSBundle mainBundle]]; } -+ (instancetype) imageNamed:(NSString*) name inBundle:(NSBundle*) bundle ++ (instancetype)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle { // Defaults - NSString* pathName = name; - NSString* pathType = @"pdf"; - - NSString* suffix = @".pdf"; + NSString *pathName = name; + NSString *pathType = @"pdf"; + + NSString *suffix = @".pdf"; const NSUInteger suffixLength = suffix.length; - + // Enough room for the suffix - if(name.length >= suffix.length) + if (name.length >= suffix.length) { const NSRange suffixRange = NSMakeRange(name.length - suffixLength, suffixLength); - + // It has it's own suffix provided in the name, split the extension (type) from the name - if([name rangeOfString:suffix options:(NSCaseInsensitiveSearch) range:suffixRange].location != NSNotFound) + if ([name rangeOfString:suffix options:(NSCaseInsensitiveSearch)range:suffixRange].location != NSNotFound) { - NSString* extensionSeparator = @"."; + NSString *extensionSeparator = @"."; const NSUInteger extensionSeparatorLength = extensionSeparator.length; - + const NSRange extensionRange = NSMakeRange(suffixRange.location + extensionSeparatorLength, suffixRange.length - extensionSeparatorLength); - NSString* extension = [name substringWithRange:extensionRange]; - + NSString *extension = [name substringWithRange:extensionRange]; + // Make sure we use what's provided in case it's not the same (lower)case as we expect pathName = [name substringToIndex:suffixRange.location]; pathType = extension; } } - + return [self imageResource:pathName ofType:pathType inBundle:bundle]; } -+ (instancetype) imageResource:(NSString*) name ofType:(NSString*) type inBundle:(NSBundle*) bundle ++ (instancetype)imageResource:(NSString *)name ofType:(NSString *)type inBundle:(NSBundle *)bundle { - NSString* filepath = [bundle pathForResource:name ofType:type]; - NSString* cacheKey = filepath; - + NSString *filepath = [bundle pathForResource:name ofType:type]; + NSString *cacheKey = filepath; + static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - sharedPDFImageCache = [[NSCache alloc] init]; + sharedPDFImageCache = [NSCache new]; }); - - PDFImage* result = [sharedPDFImageCache objectForKey:cacheKey]; - - if(result == nil) + + PDFImage *result = [sharedPDFImageCache objectForKey:cacheKey]; + + if (result == nil) { - result = [(PDFImage*)[self alloc] initWithContentsOfFile:filepath]; - - if(result != nil) + result = [(PDFImage *)[self alloc] initWithContentsOfFile:filepath]; + + if (result != nil) + { [sharedPDFImageCache setObject:result forKey:cacheKey]; + } } - + return result; } -+ (instancetype) imageWithContentsOfFile:(NSString*) path ++ (instancetype)imageWithContentsOfFile:(NSString *)path { - return [(PDFImage*)[self alloc] initWithContentsOfFile:path]; + return [(PDFImage *)[self alloc] initWithContentsOfFile:path]; } -+ (instancetype) imageWithData:(NSData*) data ++ (instancetype)imageWithData:(NSData *)data { - return [(PDFImage*)[self alloc] initWithData:data]; + return [(PDFImage *)[self alloc] initWithData:data]; } -- (instancetype) initWithContentsOfFile:(NSString*) path +- (instancetype)initWithContentsOfFile:(NSString *)path { - NSData* data = [[NSData alloc] initWithContentsOfFile:path]; + NSData *data = [[NSData alloc] initWithContentsOfFile:path]; return [self initWithData:data]; } -- (instancetype) initWithData:(NSData*) data +- (instancetype)initWithData:(NSData *)data { CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data); CGPDFDocumentRef document = CGPDFDocumentCreateWithProvider(provider); CGDataProviderRelease(provider); - + id result = [self initWithDocument:document]; - - if(document != nil) + + if (document != nil) CGPDFDocumentRelease(document); - + return result; } -- (instancetype) initWithDocument:(CGPDFDocumentRef) document +- (instancetype)initWithDocument:(CGPDFDocumentRef)document { - if(document == nil) + if (document == nil) return nil; - + self = [super init]; - - if(self != nil) + + if (self != nil) { _document = CGPDFDocumentRetain(document); _page = CGPDFDocumentGetPage(_document, 1); - + _size = CGPDFPageGetBoxRect(_page, kCGPDFMediaBox).size; } - + return self; } #pragma mark - #pragma mark Self -- (UIImage*) imageWithOptions:(PDFImageOptions*) options +- (UIImage *)imageWithOptions:(PDFImageOptions *)options { // Where to draw the image const CGRect rect = [options contentBoundsForContentSize:self.size]; - + const CGFloat scale = options.scale; - UIColor* tintColor = [options.tintColor copy]; + UIColor *tintColor = [options.tintColor copy]; const CGSize containerSize = options.size; - - NSString* cacheKey = [NSString stringWithFormat:@"%@-%0.2f-%@-%@", NSStringFromCGRect(rect), scale, tintColor.description, NSStringFromCGSize(containerSize)]; - + + NSString *cacheKey = [NSString stringWithFormat:@"%@-%0.2f-%@-%@", NSStringFromCGRect(rect), scale, tintColor.description, NSStringFromCGSize(containerSize)]; + dispatch_once(&_imageCacheOnceToken, ^{ - _imageCache = [[NSCache alloc] init]; + _imageCache = [NSCache new]; }); - - UIImage* image = [_imageCache objectForKey:cacheKey]; - - if(image == nil) + + UIImage *image = [_imageCache objectForKey:cacheKey]; + + if (image == nil) { UIGraphicsBeginImageContextWithOptions(containerSize, NO, scale); - + CGContextRef ctx = UIGraphicsGetCurrentContext(); - + [self drawInRect:rect]; - - if(tintColor != nil) + + if (tintColor != nil) { CGContextSaveGState(ctx); - + // Color the image CGContextSetBlendMode(ctx, kCGBlendModeSourceIn); CGContextSetFillColorWithColor(ctx, tintColor.CGColor); CGContextFillRect(ctx, CGRectMake(0, 0, containerSize.width, containerSize.height)); - + CGContextRestoreGState(ctx); } - + image = UIGraphicsGetImageFromCurrentImageContext(); - + UIGraphicsEndImageContext(); - - if(image != nil) + + if (image != nil) + { [_imageCache setObject:image forKey:cacheKey]; + } } - + return image; } -- (void) drawInRect:(CGRect) rect +- (void)drawInRect:(CGRect)rect { const CGSize drawSize = rect.size; const CGSize size = self.size; const CGSize sizeRatio = CGSizeMake(size.width / drawSize.width, size.height / drawSize.height); - + CGContextRef ctx = UIGraphicsGetCurrentContext(); - + CGContextSaveGState(ctx); - + // Flip and crop to the correct position and size CGContextScaleCTM(ctx, 1 / sizeRatio.width, 1 / -sizeRatio.height); CGContextTranslateCTM(ctx, rect.origin.x * sizeRatio.width, (-drawSize.height - rect.origin.y) * sizeRatio.height); - + CGContextDrawPDFPage(ctx, self.page); - + CGContextRestoreGState(ctx); } #pragma mark - #pragma mark Cleanup -- (void) dealloc +- (void)dealloc { - if(_document != nil) + if (_document != nil) { CGPDFDocumentRelease(_document); _document = nil; diff --git a/Xcode/PDFImage/PDFImageOptions.h b/Xcode/PDFImage/PDFImageOptions.h index 49e91d9..5a0c85b 100644 --- a/Xcode/PDFImage/PDFImageOptions.h +++ b/Xcode/PDFImage/PDFImageOptions.h @@ -29,17 +29,17 @@ @interface PDFImageOptions : NSObject -@property (nonatomic, assign) CGFloat scale; // screen scale, defaults to 0, the current screen scale -@property (nonatomic, copy) UIColor* tintColor; // solid color of the image, defaults to nil, original color -@property (nonatomic, assign) CGSize size; // size of the image -@property (nonatomic, assign) UIViewContentMode contentMode; // defaults to UIViewContentModeScaleToFill +@property (nonatomic, assign) CGFloat scale; // screen scale, defaults to 0, the current screen scale +@property (nonatomic, copy) UIColor *tintColor; // solid color of the image, defaults to nil, original color +@property (nonatomic, assign) CGSize size; // size of the image +@property (nonatomic, assign) UIViewContentMode contentMode; // defaults to UIViewContentModeScaleToFill // Convience method for simply spitting out a sized version -+ (instancetype) optionsWithSize:(CGSize) size; ++ (instancetype)optionsWithSize:(CGSize)size; -- (CGRect) contentBoundsForContentSize:(CGSize) contentSize; +- (CGRect)contentBoundsForContentSize:(CGSize)contentSize; // Proportionally scaled up or down by a whole number to fit the contentSize in the self.size -- (CGSize) wholeProportionalFitForContentSize:(CGSize) contentSize; +- (CGSize)wholeProportionalFitForContentSize:(CGSize)contentSize; @end diff --git a/Xcode/PDFImage/PDFImageOptions.m b/Xcode/PDFImage/PDFImageOptions.m index a184b31..17ecc89 100644 --- a/Xcode/PDFImage/PDFImageOptions.m +++ b/Xcode/PDFImage/PDFImageOptions.m @@ -29,62 +29,62 @@ @implementation PDFImageOptions -+ (instancetype) optionsWithSize:(CGSize) size ++ (instancetype)optionsWithSize:(CGSize)size { - PDFImageOptions* options = [[self alloc] init]; - [options setSize:size]; + PDFImageOptions *options = [self new]; + options.size = size; return options; } #pragma mark - -- (instancetype) init +- (instancetype)init { self = [super init]; - - if(self != nil) + + if (self != nil) { _contentMode = UIViewContentModeScaleToFill; } - + return self; } #pragma mark - #pragma mark Self -- (CGRect) contentBoundsForContentSize:(CGSize) contentSize +- (CGRect)contentBoundsForContentSize:(CGSize)contentSize { const CGSize containerSize = self.size; const UIViewContentMode contentMode = self.contentMode; - + CGRect rect = CGRectZero; - + BOOL shouldCenterWidth = NO; BOOL shouldCenterHeight = NO; - - switch(contentMode) + + switch (contentMode) { - case UIViewContentModeScaleToFill: // Scaled unproportionally to fill entire area (no gaps, no clipping) + case UIViewContentModeScaleToFill: // Scaled unproportionally to fill entire area (no gaps, no clipping) case UIViewContentModeRedraw: rect.size = containerSize; break; - - case UIViewContentModeScaleAspectFill: // Scaled proportionally to fill entire area (no gaps, with clipping) - case UIViewContentModeScaleAspectFit: // Scaled proportionally to fill entire area (with gaps, no clipping) + + case UIViewContentModeScaleAspectFill: // Scaled proportionally to fill entire area (no gaps, with clipping) + case UIViewContentModeScaleAspectFit: // Scaled proportionally to fill entire area (with gaps, no clipping) { shouldCenterWidth = YES; shouldCenterHeight = YES; - + const CGFloat widthRatio = contentSize.width / containerSize.width; const CGFloat heightRatio = contentSize.height / containerSize.height; - + const CGFloat ratio = ((contentMode == UIViewContentModeScaleAspectFill) ? MIN(widthRatio, heightRatio) : MAX(widthRatio, heightRatio)); rect.size = CGSizeMake(ceilf(contentSize.width / ratio), ceilf(contentSize.height / ratio)); - + break; } - + case UIViewContentModeCenter: case UIViewContentModeTop: case UIViewContentModeBottom: @@ -96,70 +96,70 @@ - (CGRect) contentBoundsForContentSize:(CGSize) contentSize case UIViewContentModeBottomRight: { rect.size = contentSize; - + // X positioning - switch(contentMode) + switch (contentMode) { case UIViewContentModeCenter: case UIViewContentModeTop: case UIViewContentModeBottom: shouldCenterWidth = YES; break; - + case UIViewContentModeRight: case UIViewContentModeTopRight: case UIViewContentModeBottomRight: rect.origin.x = containerSize.width - rect.size.width; break; - + default: break; } - + // Y positioning - switch(contentMode) + switch (contentMode) { case UIViewContentModeCenter: case UIViewContentModeLeft: case UIViewContentModeRight: shouldCenterHeight = YES; break; - + case UIViewContentModeBottom: case UIViewContentModeBottomLeft: case UIViewContentModeBottomRight: rect.origin.y = containerSize.height - rect.size.height; break; - + default: break; } - + break; } } - - if(shouldCenterWidth) + + if (shouldCenterWidth) rect.origin.x = floorf((containerSize.width - rect.size.width) / 2); - - if(shouldCenterHeight) + + if (shouldCenterHeight) rect.origin.y = floorf((containerSize.height - rect.size.height) / 2); - + return rect; } -- (CGSize) wholeProportionalFitForContentSize:(CGSize) contentSize +- (CGSize)wholeProportionalFitForContentSize:(CGSize)contentSize { const CGSize containerSize = self.size; - - if(contentSize.width > containerSize.width || contentSize.height > containerSize.height) + + if (contentSize.width > containerSize.width || contentSize.height > containerSize.height) { const CGFloat ratio = ceilf(MAX(contentSize.width / containerSize.width, contentSize.height / containerSize.height)); return CGSizeMake(contentSize.width / ratio, contentSize.height / ratio); } else { - + const CGFloat ratio = floorf(MIN(containerSize.width / contentSize.width, containerSize.height / contentSize.height)); return CGSizeMake(contentSize.width * ratio, contentSize.height * ratio); } diff --git a/Xcode/PDFImage/PDFImageView.h b/Xcode/PDFImage/PDFImageView.h index d1100bd..5c4ac9f 100644 --- a/Xcode/PDFImage/PDFImageView.h +++ b/Xcode/PDFImage/PDFImageView.h @@ -31,10 +31,10 @@ @interface PDFImageView : UIView -@property (nonatomic, strong) PDFImage* image; -@property (nonatomic, copy) UIColor* tintColor; +@property (nonatomic, strong) PDFImage *image; +@property (nonatomic, copy) UIColor *tintColor; // Returns the current UIImage based on frame, tint, etc etc -- (UIImage*) currentUIImage; +@property (nonatomic, readonly) UIImage *currentUIImage; @end diff --git a/Xcode/PDFImage/PDFImageView.m b/Xcode/PDFImage/PDFImageView.m index 8b397ca..dbbe311 100644 --- a/Xcode/PDFImage/PDFImageView.m +++ b/Xcode/PDFImage/PDFImageView.m @@ -34,70 +34,70 @@ @interface PDFImageView () // Bridged options from our properties -@property (nonatomic, readonly) PDFImageOptions* options; +@property (nonatomic, readonly) PDFImageOptions *options; -@property (nonatomic, readonly) UIImageView* imageView; +@property (nonatomic, readonly) UIImageView *imageView; @end @implementation PDFImageView -- (instancetype) initWithFrame:(CGRect)frame +- (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; - - if(self != nil) + + if (self != nil) { - [self setBackgroundColor:[UIColor clearColor]]; - - _options = [[PDFImageOptions alloc] init]; - [_options setContentMode:self.contentMode]; - - _imageView = [[UIImageView alloc] init]; - [_imageView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + self.backgroundColor = [UIColor clearColor]; + + _options = [PDFImageOptions new]; + _options.contentMode = self.contentMode; + + _imageView = [UIImageView new]; + _imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); [self addSubview:_imageView]; } - + return self; } #pragma mark - #pragma mark Super -- (void) layoutSubviews +- (void)layoutSubviews { [super layoutSubviews]; - - CGRect imageViewFrame = self.bounds; - [self.imageView setFrame:imageViewFrame]; + + const CGRect imageViewFrame = self.bounds; + self.imageView.frame = imageViewFrame; } -- (void) drawRect:(CGRect)rect +- (void)drawRect:(CGRect)rect { [super drawRect:rect]; - - [self.imageView setImage:self.currentUIImage]; + + self.imageView.image = self.currentUIImage; } -- (void) setContentMode:(UIViewContentMode)contentMode +- (void)setContentMode:(UIViewContentMode)contentMode { [super setContentMode:contentMode]; - - [self.options setContentMode:contentMode]; - + + self.options.contentMode = contentMode; + [self setNeedsDisplay]; } -- (void) willMoveToWindow:(UIWindow *)newWindow +- (void)willMoveToWindow:(UIWindow *)newWindow { [super willMoveToWindow:newWindow]; - + // Set the scale to that of the window's screen // The scale would only change if the image view is added to an external UIScreen - [self.options setScale:newWindow.screen.scale]; + self.options.scale = newWindow.screen.scale; } -+ (Class) layerClass ++ (Class)layerClass { return [PDFImageViewLayer class]; } @@ -105,35 +105,35 @@ + (Class) layerClass #pragma mark - #pragma mark Self -- (void) setImage:(PDFImage *)image +- (void)setImage:(PDFImage *)image { _image = image; - + [self setNeedsDisplay]; } -- (UIColor*) tintColor +- (UIColor *)tintColor { return self.options.tintColor; } -- (void) setTintColor:(UIColor *)tintColor +- (void)setTintColor:(UIColor *)tintColor { - [self.options setTintColor:tintColor]; - + self.options.tintColor = tintColor; + [self setNeedsDisplay]; } -- (UIImage*) currentUIImage +- (UIImage *)currentUIImage { - [self.options setSize:self.frame.size]; - - if(!CGSizeEqualToSize(self.options.size, CGSizeZero)) + self.options.size = self.frame.size; + + if (!CGSizeEqualToSize(self.options.size, CGSizeZero)) { - UIImage* currentUIImage = [self.image imageWithOptions:self.options]; + UIImage *currentUIImage = [self.image imageWithOptions:self.options]; return currentUIImage; } - + return nil; } diff --git a/Xcode/PDFImage/PDFImageViewLayer.m b/Xcode/PDFImage/PDFImageViewLayer.m index 90f52f6..d2edb52 100644 --- a/Xcode/PDFImage/PDFImageViewLayer.m +++ b/Xcode/PDFImage/PDFImageViewLayer.m @@ -29,7 +29,7 @@ @interface PDFImageViewLayer () -@property (nonatomic, strong) CAAnimation* lastSizeAnimation; +@property (nonatomic, strong) CAAnimation *lastSizeAnimation; @end @@ -38,49 +38,55 @@ @implementation PDFImageViewLayer #pragma mark - #pragma mark Super -- (void) setFrame:(CGRect)frame +- (void)setFrame:(CGRect)frame { const CGRect currentFrame = self.frame; - + const BOOL newFrameIsBigger = (frame.size.width > currentFrame.size.width || frame.size.height > currentFrame.size.height); - - [self setLastSizeAnimation:nil]; - + + self.lastSizeAnimation = nil; + [super setFrame:frame]; - + // Delay a redraw for smooth transition when animating size const CGFloat redrawOffset = ((newFrameIsBigger) ? 0 : 0.9); const NSTimeInterval delay = self.lastSizeAnimation.duration * redrawOffset + self.lastSizeAnimation.beginTime; - - if(delay > 0) + + if (delay > 0) + { [self performSelector:@selector(delayedSetNeedsDisplay) withObject:nil afterDelay:delay]; + } else + { [self setNeedsDisplay]; - + } + // Clear what we found - [self setLastSizeAnimation:nil]; + self.lastSizeAnimation = nil; } -- (void) addAnimation:(CAAnimation *)anim forKey:(NSString *)key +- (void)addAnimation:(CAAnimation *)anim forKey:(NSString *)key { [super addAnimation:anim forKey:key]; - - if([anim isKindOfClass:[CAPropertyAnimation class]]) + + if ([anim isKindOfClass:[CAPropertyAnimation class]]) { - CAPropertyAnimation* propertyAnimation = (id)anim; - + CAPropertyAnimation *propertyAnimation = (id)anim; + // If we're animating the size, mark the duration (for use in the setFrame: method) - if([propertyAnimation.keyPath isEqualToString:@"bounds"] || // iOS <= 7 animation key - [propertyAnimation.keyPath isEqualToString:@"bounds.size"]) // iOS >= 8 animation key - [self setLastSizeAnimation:anim]; + if ([propertyAnimation.keyPath isEqualToString:@"bounds"] || // iOS <= 7 animation key + [propertyAnimation.keyPath isEqualToString:@"bounds.size"]) // iOS >= 8 animation key + { + self.lastSizeAnimation = anim; + } } } #pragma mark - #pragma mark Private -- (void) delayedSetNeedsDisplay +- (void)delayedSetNeedsDisplay { [self setNeedsDisplay]; } diff --git a/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFNavigationController.m b/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFNavigationController.m index ae60927..85d90f1 100644 --- a/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFNavigationController.m +++ b/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFNavigationController.m @@ -33,6 +33,4 @@ @interface PDFNavigationController () @implementation PDFNavigationController - - @end diff --git a/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFViewController.h b/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFViewController.h index 920b14c..adf1d51 100644 --- a/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFViewController.h +++ b/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFViewController.h @@ -29,6 +29,6 @@ @interface PDFViewController : UIViewController -@property (nonatomic, copy) NSString* info; +@property (nonatomic, copy) NSString *info; @end diff --git a/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFViewController.m b/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFViewController.m index 0a99214..ded70ef 100644 --- a/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFViewController.m +++ b/Xcode/PDFImageDemo/Classes/Controllers/Abstract/PDFViewController.m @@ -28,54 +28,52 @@ #import "PDFViewController.h" @interface PDFViewController () -{ - UILabel* _infoLabel; -} -- (UILabel*) infoLabel; +@property (nonatomic, readonly) UILabel *infoLabel; @end @implementation PDFViewController @dynamic info; +@synthesize infoLabel = _infoLabel; -- (void) viewDidLoad +- (void)viewDidLoad { [super viewDidLoad]; - - [self.view setBackgroundColor:[UIColor whiteColor]]; + + self.view.backgroundColor = [UIColor whiteColor]; } -- (void) viewDidLayoutSubviews +- (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; - - if(_infoLabel != nil) + + if (_infoLabel != nil) { - UILabel* infoLabel = _infoLabel; - + UILabel *infoLabel = _infoLabel; + CGRect infoLabelFrame = CGRectZero; infoLabelFrame.origin.x = 10; infoLabelFrame.size.width = self.view.frame.size.width - infoLabelFrame.origin.x * 2; - infoLabelFrame.size.height = ceilf([infoLabel.text sizeWithFont:infoLabel.font constrainedToSize:CGSizeMake(infoLabelFrame.size.width, CGFLOAT_MAX) lineBreakMode:infoLabel.lineBreakMode].height); + infoLabelFrame.size.height = [infoLabel sizeThatFits:CGSizeMake(infoLabelFrame.size.width, CGFLOAT_MAX)].height; infoLabelFrame.origin.y = self.view.frame.size.height - infoLabelFrame.size.height - 10; - - [infoLabel setFrame:infoLabelFrame]; + + infoLabel.frame = infoLabelFrame; } } #pragma mark - #pragma mark Self -- (void) setInfo:(NSString *)info +- (void)setInfo:(NSString *)info { - [self.infoLabel setText:info]; - + self.infoLabel.text = info; + [self.view setNeedsLayout]; } -- (NSString*) info +- (NSString *)info { return _infoLabel.text; } @@ -83,19 +81,19 @@ - (NSString*) info #pragma mark - #pragma mark Private -- (UILabel*) infoLabel +- (UILabel *)infoLabel { - if(_infoLabel == nil) + if (_infoLabel == nil) { - _infoLabel = [[UILabel alloc] init]; - [_infoLabel setNumberOfLines:0]; - [_infoLabel setFont:[UIFont systemFontOfSize:17]]; - [_infoLabel setTextColor:[UIColor colorWithWhite:0.2 alpha:1]]; + _infoLabel = [UILabel new]; + _infoLabel.numberOfLines = 0; + _infoLabel.font = [UIFont systemFontOfSize:17]; + _infoLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1]; [self.view addSubview:_infoLabel]; - + [self.view setNeedsLayout]; } - + return _infoLabel; } diff --git a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFAnimationDemoViewController.m b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFAnimationDemoViewController.m index 407f944..6d81303 100644 --- a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFAnimationDemoViewController.m +++ b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFAnimationDemoViewController.m @@ -30,72 +30,74 @@ #import @interface PDFAnimationDemoViewController () -{ - PDFImageView* imageView; - - CGRect frame1; - CGRect frame2; -} -- (void) animate; -- (void) animate:(BOOL) toFrom; +@property (nonatomic, readonly) PDFImageView *imageView; + +@property (nonatomic, readonly) CGRect frame1; +@property (nonatomic, readonly) CGRect frame2; @end @implementation PDFAnimationDemoViewController -- (void) viewDidLoad +- (void)viewDidLoad { [super viewDidLoad]; - - [self setTitle:@"PDFImageView Animation"]; - [self setInfo:@"When animated, the PDFImageView redraws itself just once, but timed smartly to give the illusion of a smooth image for the entire animation"]; - - PDFImage* image = [PDFImage imageNamed:@"11"]; - + + self.title = @"PDFImageView Animation"; + self.info = @"When animated, the PDFImageView redraws itself just once, but timed smartly to give the illusion of a smooth image for the entire animation"; + + PDFImage *image = [PDFImage imageNamed:@"11"]; + const CGFloat scale1 = 1; const CGFloat scale2 = 30; - - frame1 = CGRectMake(40, 80, image.size.width, image.size.height); + + CGRect frame1 = CGRectMake(40, 80, image.size.width, image.size.height); frame1.size.width *= scale1; frame1.size.height *= scale1; - - frame2 = frame1; + _frame1 = frame1; + + CGRect frame2 = frame1; frame2.size.width *= scale2; frame2.size.height *= scale2; - - imageView = [[PDFImageView alloc] initWithFrame:frame1]; - [imageView setImage:image]; - [imageView setTintColor:[UIColor colorWithRed:0 green:0 blue:0.8 alpha:1]]; - [self.view addSubview:imageView]; + _frame2 = frame2; + + _imageView = [[PDFImageView alloc] initWithFrame:frame1]; + _imageView.image = image; + _imageView.tintColor = [UIColor colorWithRed:0 green:0 blue:0.8 alpha:1]; + [self.view addSubview:_imageView]; } -- (void) viewDidAppear:(BOOL)animated +- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - + [self animate]; } #pragma mark - #pragma mark Private -- (void) animate +- (void)animate { [self animate:YES]; } -- (void) animate:(BOOL) toFrom +- (void)animate:(BOOL)toFrom { - [UIView animateWithDuration:1 delay:0.5 options:0 animations:^{ - - [imageView setFrame:((toFrom) ? frame2 : frame1)]; - - } completion:^(BOOL finished) { - - if(finished) - [self animate:!toFrom]; - }]; + [UIView animateWithDuration:1 + delay:0.5 + options:0 + animations:^{ + + self.imageView.frame = (toFrom ? self.frame2 : self.frame1); + + } + completion:^(BOOL finished) { + + if (finished) + [self animate:!toFrom]; + }]; } @end diff --git a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFBarButtonDemoViewController.m b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFBarButtonDemoViewController.m index fe862f0..fa7316d 100644 --- a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFBarButtonDemoViewController.m +++ b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFBarButtonDemoViewController.m @@ -35,20 +35,22 @@ @interface PDFBarButtonDemoViewController () @implementation PDFBarButtonDemoViewController -- (void) viewDidLoad +- (void)viewDidLoad { [super viewDidLoad]; - - [self setInfo:@"Create a UIBarButtonItem using a PDFImage with the PDFBarButtonItem subclass"]; - - PDFBarButtonItem* button1 = [[PDFBarButtonItem alloc] initWithImage:[PDFImage imageNamed:@"3"] style:UIBarButtonItemStyleBordered target:nil action:nil]; - PDFBarButtonItem* button2 = [[PDFBarButtonItem alloc] initWithImage:[PDFImage imageNamed:@"4"] style:UIBarButtonItemStylePlain target:nil action:nil]; - PDFBarButtonItem* button3 = [[PDFBarButtonItem alloc] initWithImage:[PDFImage imageNamed:@"5"] style:UIBarButtonItemStylePlain target:nil action:nil]; - - [button1 setTintColor:[UIColor redColor]]; - [button2 setTintColor:[UIColor orangeColor]]; - - [self.navigationItem setRightBarButtonItems:@[button1, button2, button3]]; + + self.info = @"Create a UIBarButtonItem using a PDFImage with the PDFBarButtonItem subclass"; + + PDFBarButtonItem *button1 = [[PDFBarButtonItem alloc] initWithImage:[PDFImage imageNamed:@"3"] style:UIBarButtonItemStyleBordered target:nil action:nil]; + PDFBarButtonItem *button2 = [[PDFBarButtonItem alloc] initWithImage:[PDFImage imageNamed:@"4"] style:UIBarButtonItemStylePlain target:nil action:nil]; + PDFBarButtonItem *button3 = [[PDFBarButtonItem alloc] initWithImage:[PDFImage imageNamed:@"5"] style:UIBarButtonItemStylePlain target:nil action:nil]; + + button1.tintColor = [UIColor redColor]; + button2.tintColor = [UIColor orangeColor]; + + self.navigationItem.rightBarButtonItems = @[ button1, + button2, + button3 ]; } @end diff --git a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFLocalizedDemoViewController.m b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFLocalizedDemoViewController.m index cdea7a2..368d557 100644 --- a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFLocalizedDemoViewController.m +++ b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFLocalizedDemoViewController.m @@ -35,15 +35,15 @@ @interface PDFLocalizedDemoViewController () @implementation PDFLocalizedDemoViewController -- (void) viewDidLoad +- (void)viewDidLoad { [super viewDidLoad]; - - [self setTitle:@"Localized Resources"]; - [self setInfo:@"Switch your language between English and Spanish to see a different bundle resource load"]; - - PDFImageView* imageView = [[PDFImageView alloc] initWithFrame:CGRectMake(40, 80, 220, 100)]; - [imageView setImage:[PDFImage imageNamed:@"locale"]]; + + self.title = @"Localized Resources"; + self.info = @"Switch your language between English and Spanish to see a different bundle resource load"; + + PDFImageView *imageView = [[PDFImageView alloc] initWithFrame:CGRectMake(40, 80, 220, 100)]; + imageView.image = [PDFImage imageNamed:@"locale"]; [self.view addSubview:imageView]; } diff --git a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFTableViewDemoViewController.m b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFTableViewDemoViewController.m index 7bc97a1..71df53b 100644 --- a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFTableViewDemoViewController.m +++ b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFTableViewDemoViewController.m @@ -34,68 +34,69 @@ static const NSUInteger kDemoPDFCount = 12; @interface PDFTableViewDemoViewController () -{ - UITableView* listTableView; -} -- (PDFImage*) imageForIndexPath:(NSIndexPath*) indexPath; +@property (nonatomic, readonly) UITableView *listTableView; @end @implementation PDFTableViewDemoViewController -- (void) viewDidLoad +- (void)viewDidLoad { [super viewDidLoad]; - - [self setTitle:@"UITableView Performance"]; - - listTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; - [listTableView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; - [listTableView setDataSource:self]; - [self.view addSubview:listTableView]; + + self.title = @"UITableView Performance"; + + _listTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; + _listTableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); + _listTableView.dataSource = self; + [self.view addSubview:_listTableView]; } #pragma mark - #pragma mark Private -- (PDFImage*) imageForIndexPath:(NSIndexPath*) indexPath +- (PDFImage *)imageForIndexPath:(NSIndexPath *)indexPath { - NSString* filename = @(indexPath.row % kDemoPDFCount).stringValue; - PDFImage* image = [PDFImage imageNamed:filename]; + NSString *filename = @(indexPath.row % kDemoPDFCount).stringValue; + PDFImage *image = [PDFImage imageNamed:filename]; return image; } #pragma mark - #pragma mark UITableView Delegate -- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1000; } -- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - static NSString* identifier = @"listCell"; - - PDFImageViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier]; - - if(cell == nil) + static NSString *identifier = @"listCell"; + + PDFImageViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; + + if (cell == nil) { cell = [[PDFImageViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; - [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; - - UIColor* tintColor = [UIColor colorWithRed:0.8 green:0 blue:0 alpha:1]; - - for(PDFImageView* pdfImageView in cell.pdfImageViews) - [pdfImageView setTintColor:tintColor]; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + + UIColor *tintColor = [UIColor colorWithRed:0.8 green:0 blue:0 alpha:1]; + + for (PDFImageView *pdfImageView in cell.pdfImageViews) + { + pdfImageView.tintColor = tintColor; + } + } + + PDFImage *image = [self imageForIndexPath:indexPath]; + + for (PDFImageView *pdfImageView in cell.pdfImageViews) + { + pdfImageView.image = image; } - - PDFImage* image = [self imageForIndexPath:indexPath]; - - for(PDFImageView* pdfImageView in cell.pdfImageViews) - [pdfImageView setImage:image]; - + return cell; } diff --git a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFTintColorDemoViewController.m b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFTintColorDemoViewController.m index a9a0314..0e10b34 100644 --- a/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFTintColorDemoViewController.m +++ b/Xcode/PDFImageDemo/Classes/Controllers/Demos/PDFTintColorDemoViewController.m @@ -35,22 +35,22 @@ @interface PDFTintColorDemoViewController () @implementation PDFTintColorDemoViewController -- (void) viewDidLoad +- (void)viewDidLoad { [super viewDidLoad]; - - [self setTitle:@"Tint Color"]; - [self setInfo:@"The same PDF file is used, however only the second image view uses a tint color"]; - - PDFImage* image = [PDFImage imageNamed:@"tint"]; - - PDFImageView* imageView1 = [[PDFImageView alloc] initWithFrame:CGRectMake(40, 80, 220, 100)]; - [imageView1 setImage:image]; + + self.title = @"Tint Color"; + self.info = @"The same PDF file is used, however only the second image view uses a tint color"; + + PDFImage *image = [PDFImage imageNamed:@"tint"]; + + PDFImageView *imageView1 = [[PDFImageView alloc] initWithFrame:CGRectMake(40, 80, 220, 100)]; + imageView1.image = image; [self.view addSubview:imageView1]; - - PDFImageView* imageView2 = [[PDFImageView alloc] initWithFrame:CGRectMake(40, 200, 220, 100)]; - [imageView2 setImage:image]; - [imageView2 setTintColor:[UIColor purpleColor]]; + + PDFImageView *imageView2 = [[PDFImageView alloc] initWithFrame:CGRectMake(40, 200, 220, 100)]; + imageView2.image = image; + imageView2.tintColor = [UIColor purpleColor]; [self.view addSubview:imageView2]; } diff --git a/Xcode/PDFImageDemo/Classes/Controllers/Root/PDFDemoListViewController.m b/Xcode/PDFImageDemo/Classes/Controllers/Root/PDFDemoListViewController.m index d30ea28..f050e57 100644 --- a/Xcode/PDFImageDemo/Classes/Controllers/Root/PDFDemoListViewController.m +++ b/Xcode/PDFImageDemo/Classes/Controllers/Root/PDFDemoListViewController.m @@ -43,113 +43,120 @@ typedef NS_ENUM(NSUInteger, PDFDemo) }; @interface PDFDemoListViewController () -{ - NSArray* demos; - UITableView* demoTableView; -} -- (PDFDemo) demoForIndexPath:(NSIndexPath*) indexPath; -- (NSString*) nameForDemo:(PDFDemo) demo; -- (Class) classForDemo:(PDFDemo) demo; +@property (nonatomic, readonly) NSArray *demos; +@property (nonatomic, readonly) UITableView *demoTableView; @end @implementation PDFDemoListViewController -- (void) viewDidLoad +- (void)viewDidLoad { [super viewDidLoad]; - - [self setTitle:@"PDFImage Demo List"]; - + + self.title = @"PDFImage Demo List"; + // Demo order - demos = @[@(PDFDemoTintColor), @(PDFDemoTableView), @(PDFDemoAnimation), @(PDFDemoLocalized), @(PDFDemoBarButton)]; - - demoTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; - [demoTableView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; - [demoTableView setDataSource:self]; - [demoTableView setDelegate:self]; - [self.view addSubview:demoTableView]; + _demos = @[ @(PDFDemoTintColor), + @(PDFDemoTableView), + @(PDFDemoAnimation), + @(PDFDemoLocalized), + @(PDFDemoBarButton) ]; + + _demoTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; + _demoTableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); + _demoTableView.dataSource = self; + _demoTableView.delegate = self; + [self.view addSubview:_demoTableView]; } -- (void) viewWillAppear:(BOOL)animated +- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - - if(demoTableView.indexPathForSelectedRow != nil) - [demoTableView deselectRowAtIndexPath:demoTableView.indexPathForSelectedRow animated:YES]; + + if (self.demoTableView.indexPathForSelectedRow != nil) + { + [self.demoTableView deselectRowAtIndexPath:self.demoTableView.indexPathForSelectedRow animated:YES]; + } } #pragma mark - #pragma mark Private -- (PDFDemo) demoForIndexPath:(NSIndexPath*) indexPath +- (PDFDemo)demoForIndexPath:(NSIndexPath *)indexPath { - const PDFDemo demo = [[demos objectAtIndex:indexPath.row] unsignedIntegerValue]; + const PDFDemo demo = [self.demos[indexPath.row] unsignedIntegerValue]; return demo; } -- (NSString*) nameForDemo:(PDFDemo) demo +- (NSString *)nameForDemo:(PDFDemo)demo { - switch(demo) + switch (demo) { - case PDFDemoTintColor: return @"Tint Color"; - case PDFDemoTableView: return @"UITableView Performance"; - case PDFDemoAnimation: return @"PDFImageView Animation"; - case PDFDemoLocalized: return @"Localized Resources"; - case PDFDemoBarButton: return @"UIBarButtonItem"; + case PDFDemoTintColor: + return @"Tint Color"; + case PDFDemoTableView: + return @"UITableView Performance"; + case PDFDemoAnimation: + return @"PDFImageView Animation"; + case PDFDemoLocalized: + return @"Localized Resources"; + case PDFDemoBarButton: + return @"UIBarButtonItem"; } - - return nil; } -- (Class) classForDemo:(PDFDemo) demo +- (Class)classForDemo:(PDFDemo)demo { - switch(demo) + switch (demo) { - case PDFDemoTintColor: return [PDFTintColorDemoViewController class]; - case PDFDemoTableView: return [PDFTableViewDemoViewController class]; - case PDFDemoAnimation: return [PDFAnimationDemoViewController class]; - case PDFDemoLocalized: return [PDFLocalizedDemoViewController class]; - case PDFDemoBarButton: return [PDFBarButtonDemoViewController class]; + case PDFDemoTintColor: + return [PDFTintColorDemoViewController class]; + case PDFDemoTableView: + return [PDFTableViewDemoViewController class]; + case PDFDemoAnimation: + return [PDFAnimationDemoViewController class]; + case PDFDemoLocalized: + return [PDFLocalizedDemoViewController class]; + case PDFDemoBarButton: + return [PDFBarButtonDemoViewController class]; } - - return nil; } #pragma mark - -#pragma mark UITableView Delegate +#pragma mark UITableViewDelegate -- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { const PDFDemo demo = [self demoForIndexPath:indexPath]; Class class = [self classForDemo:demo]; - - UIViewController* viewController = [[class alloc] init]; + + UIViewController *viewController = [class new]; [self.navigationController pushViewController:viewController animated:YES]; } -- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return demos.count; + return self.demos.count; } -- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - static NSString* identifier = @"demoCell"; - - UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier]; - - if(cell == nil) + static NSString *const identifier = @"demoCell"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; + + if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } - + const PDFDemo demo = [self demoForIndexPath:indexPath]; - NSString* name = [self nameForDemo:demo]; - - [cell.textLabel setText:name]; - + NSString *name = [self nameForDemo:demo]; + + cell.textLabel.text = name; + return cell; } diff --git a/Xcode/PDFImageDemo/Classes/PDFAppDelegate.m b/Xcode/PDFImageDemo/Classes/PDFAppDelegate.m index 401f871..e929146 100644 --- a/Xcode/PDFImageDemo/Classes/PDFAppDelegate.m +++ b/Xcode/PDFImageDemo/Classes/PDFAppDelegate.m @@ -38,16 +38,16 @@ @implementation PDFAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - [window setBackgroundColor:[UIColor whiteColor]]; - - PDFDemoListViewController* demoViewController = [[PDFDemoListViewController alloc] init]; - PDFNavigationController* navigationController = [[PDFNavigationController alloc] initWithRootViewController:demoViewController]; - - [window setRootViewController:navigationController]; - + window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; + window.backgroundColor = [UIColor whiteColor]; + + PDFDemoListViewController *demoViewController = [PDFDemoListViewController new]; + PDFNavigationController *navigationController = [[PDFNavigationController alloc] initWithRootViewController:demoViewController]; + + window.rootViewController = navigationController; + [window makeKeyAndVisible]; - + return YES; } diff --git a/Xcode/PDFImageDemo/Classes/Table Cells/PDFImageViewCell.h b/Xcode/PDFImageDemo/Classes/Table Cells/PDFImageViewCell.h index b78ad49..ea6261e 100644 --- a/Xcode/PDFImageDemo/Classes/Table Cells/PDFImageViewCell.h +++ b/Xcode/PDFImageDemo/Classes/Table Cells/PDFImageViewCell.h @@ -31,6 +31,6 @@ @interface PDFImageViewCell : UITableViewCell -@property (nonatomic, readonly) NSArray* pdfImageViews; // array of PDFImageView +@property (nonatomic, readonly) NSArray *pdfImageViews; // array of PDFImageView @end diff --git a/Xcode/PDFImageDemo/Classes/Table Cells/PDFImageViewCell.m b/Xcode/PDFImageDemo/Classes/Table Cells/PDFImageViewCell.m index 98da894..032c612 100644 --- a/Xcode/PDFImageDemo/Classes/Table Cells/PDFImageViewCell.m +++ b/Xcode/PDFImageDemo/Classes/Table Cells/PDFImageViewCell.m @@ -33,58 +33,47 @@ @implementation PDFImageViewCell -@synthesize pdfImageViews = _pdfImageViews; - -- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier +- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; - - if(self != nil) + + if (self != nil) { - for(PDFImageView* pdfImageView in self.pdfImageViews) + NSMutableArray *mutablePDFImageViews = [NSMutableArray new]; + + for (NSUInteger i = 0; i < kImageViewCount; i++) + { + PDFImageView *pdfImageView = [PDFImageView new]; + [mutablePDFImageViews addObject:pdfImageView]; [self.contentView addSubview:pdfImageView]; + } + + _pdfImageViews = [mutablePDFImageViews copy]; } - + return self; } #pragma mark - #pragma mark Super -- (void) layoutSubviews +- (void)layoutSubviews { [super layoutSubviews]; - + const CGFloat imageViewDimension = self.contentView.frame.size.height; - - NSArray* pdfImageViews = self.pdfImageViews; - - for(NSUInteger i = 0; i < pdfImageViews.count; i++) - { - PDFImageView* pdfImageView = [pdfImageViews objectAtIndex:i]; - [pdfImageView setFrame:CGRectMake(imageViewDimension * (i + 1) + imageViewDimension * i, 0, imageViewDimension, imageViewDimension)]; - } -} -#pragma mark - -#pragma mark Self + NSArray *pdfImageViews = self.pdfImageViews; -- (NSArray*) pdfImageViews -{ - if(_pdfImageViews == nil) + for (NSUInteger i = 0; i < pdfImageViews.count; i++) { - NSMutableArray* mutablePDFImageViews = [[NSMutableArray alloc] init]; - - for(NSUInteger i = 0; i < kImageViewCount; i++) - { - PDFImageView* pdfImageView = [[PDFImageView alloc] init]; - [mutablePDFImageViews addObject:pdfImageView]; - } - - _pdfImageViews = [mutablePDFImageViews copy]; + PDFImageView *pdfImageView = pdfImageViews[i]; + + pdfImageView.frame = CGRectMake(imageViewDimension * (i + 1) + imageViewDimension * i, + 0, + imageViewDimension, + imageViewDimension); } - - return _pdfImageViews; } @end diff --git a/Xcode/PDFImageDemo/main.m b/Xcode/PDFImageDemo/main.m index 630c0b7..7d80ceb 100644 --- a/Xcode/PDFImageDemo/main.m +++ b/Xcode/PDFImageDemo/main.m @@ -29,9 +29,10 @@ #import "PDFAppDelegate.h" -int main(int argc, char * argv[]) +int main(int argc, char *argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([PDFAppDelegate class])); + @autoreleasepool + { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([PDFAppDelegate class])); } } diff --git a/Xcode/PDFImageTests/PDFImageTests.m b/Xcode/PDFImageTests/PDFImageTests.m index a6b4d3e..e3a5940 100644 --- a/Xcode/PDFImageTests/PDFImageTests.m +++ b/Xcode/PDFImageTests/PDFImageTests.m @@ -31,137 +31,137 @@ @interface PDFImageTests : XCTestCase -@property (nonatomic, readonly) NSBundle* bundle; -@property (nonatomic, readonly) UIWindow* keyWindow; +@property (nonatomic, readonly) NSBundle *bundle; +@property (nonatomic, readonly) UIWindow *keyWindow; @end @implementation PDFImageTests -- (instancetype) initWithInvocation:(NSInvocation *)invocation +- (instancetype)initWithInvocation:(NSInvocation *)invocation { self = [super initWithInvocation:invocation]; - - if(self != nil) + + if (self != nil) { _bundle = [NSBundle bundleForClass:[self class]]; _keyWindow = [UIApplication sharedApplication].keyWindow; } - + return self; } #pragma mark - #pragma mark Tests -- (void) testPDFImage +- (void)testPDFImage { - PDFImage* image = [PDFImage imageNamed:@"0" inBundle:self.bundle]; - + PDFImage *image = [PDFImage imageNamed:@"0" inBundle:self.bundle]; + XCTAssertNotNil(image, @"Failed loading pdf image"); XCTAssertEqual(image.size.width, 15.0f, @"Size not as expected"); XCTAssertEqual(image.size.height, 15.0f, @"Size not as expected"); - - PDFImage* missing = [PDFImage imageNamed:@"non-existant" inBundle:self.bundle]; - + + PDFImage *missing = [PDFImage imageNamed:@"non-existant" inBundle:self.bundle]; + XCTAssertNil(missing, @"Should not load missing files"); - - PDFImageOptions* options = [PDFImageOptions optionsWithSize:image.size]; - - UIImage* result = [image imageWithOptions:options]; - + + PDFImageOptions *options = [PDFImageOptions optionsWithSize:image.size]; + + UIImage *result = [image imageWithOptions:options]; + XCTAssertNotNil(result, @"Failed generating image"); } -- (void) testPDFImageCache +- (void)testPDFImageCache { - PDFImage* same1 = [PDFImage imageNamed:@"5" inBundle:self.bundle]; - PDFImage* same2 = [PDFImage imageNamed:@"5" inBundle:self.bundle]; - PDFImage* diff1 = [PDFImage imageNamed:@"6" inBundle:self.bundle]; - + PDFImage *same1 = [PDFImage imageNamed:@"5" inBundle:self.bundle]; + PDFImage *same2 = [PDFImage imageNamed:@"5" inBundle:self.bundle]; + PDFImage *diff1 = [PDFImage imageNamed:@"6" inBundle:self.bundle]; + XCTAssertEqual(same1, same2, @"Bundle caching should result in equal pointers"); XCTAssertNotEqual(same1, diff1, @"Different files should result in different pointers"); } -- (void) testPDFImageResultCache +- (void)testPDFImageResultCache { - PDFImage* image = [PDFImage imageNamed:@"5" inBundle:self.bundle]; - - PDFImageOptions* options = [PDFImageOptions optionsWithSize:CGSizeMake(40, 40)]; - - UIImage* same1 = [image imageWithOptions:options]; - UIImage* same2 = [image imageWithOptions:options]; - - [options setTintColor:[UIColor redColor]]; - - UIImage* diff1 = [image imageWithOptions:options]; - - [options setTintColor:nil]; - [options setContentMode:UIViewContentModeTopLeft]; - - UIImage* diff2 = [image imageWithOptions:options]; - + PDFImage *image = [PDFImage imageNamed:@"5" inBundle:self.bundle]; + + PDFImageOptions *options = [PDFImageOptions optionsWithSize:CGSizeMake(40, 40)]; + + UIImage *same1 = [image imageWithOptions:options]; + UIImage *same2 = [image imageWithOptions:options]; + + options.tintColor = [UIColor redColor]; + + UIImage *diff1 = [image imageWithOptions:options]; + + options.tintColor = nil; + options.contentMode = UIViewContentModeTopLeft; + + UIImage *diff2 = [image imageWithOptions:options]; + XCTAssertEqual(same1, same2, @"Image caching should result in equal pointers"); XCTAssertNotEqual(same1, diff1, @"Different images should result in different pointers"); XCTAssertNotEqual(same1, diff2, @"Different images should result in different pointers"); XCTAssertNotEqual(diff1, diff2, @"Different images should result in different pointers"); } -- (void) testPDFImageOptionsContentMode +- (void)testPDFImageOptionsContentMode { const CGSize containerSize = CGSizeMake(20, 20); const CGSize contentSize = CGSizeMake(5, 10); - - PDFImageOptions* options = [[PDFImageOptions alloc] init]; - [options setSize:containerSize]; - - [options setContentMode:UIViewContentModeScaleToFill]; + + PDFImageOptions *options = [PDFImageOptions new]; + options.size = containerSize; + + options.contentMode = UIViewContentModeScaleToFill; XCTAssertTrue(CGRectEqualToRect(CGRectMake(0, 0, 20, 20), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeScaleAspectFit]; + + options.contentMode = UIViewContentModeScaleAspectFit; XCTAssertTrue(CGRectEqualToRect(CGRectMake(5, 0, 10, 20), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeScaleAspectFill]; + + options.contentMode = UIViewContentModeScaleAspectFill; XCTAssertTrue(CGRectEqualToRect(CGRectMake(0, -10, 20, 40), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeRedraw]; + + options.contentMode = UIViewContentModeRedraw; XCTAssertTrue(CGRectEqualToRect(CGRectMake(0, 0, 20, 20), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeCenter]; + + options.contentMode = UIViewContentModeCenter; XCTAssertTrue(CGRectEqualToRect(CGRectMake(7, 5, 5, 10), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeTop]; + + options.contentMode = UIViewContentModeTop; XCTAssertTrue(CGRectEqualToRect(CGRectMake(7, 0, 5, 10), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeBottom]; + + options.contentMode = UIViewContentModeBottom; XCTAssertTrue(CGRectEqualToRect(CGRectMake(7, 10, 5, 10), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeLeft]; + + options.contentMode = UIViewContentModeLeft; XCTAssertTrue(CGRectEqualToRect(CGRectMake(0, 5, 5, 10), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeRight]; + + options.contentMode = UIViewContentModeRight; XCTAssertTrue(CGRectEqualToRect(CGRectMake(15, 5, 5, 10), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeTopLeft]; + + options.contentMode = UIViewContentModeTopLeft; XCTAssertTrue(CGRectEqualToRect(CGRectMake(0, 0, 5, 10), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeTopRight]; + + options.contentMode = UIViewContentModeTopRight; XCTAssertTrue(CGRectEqualToRect(CGRectMake(15, 0, 5, 10), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeBottomLeft]; + + options.contentMode = UIViewContentModeBottomLeft; XCTAssertTrue(CGRectEqualToRect(CGRectMake(0, 10, 5, 10), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); - - [options setContentMode:UIViewContentModeBottomRight]; + + options.contentMode = UIViewContentModeBottomRight; XCTAssertTrue(CGRectEqualToRect(CGRectMake(15, 10, 5, 10), [options contentBoundsForContentSize:contentSize]), @"Wrong content mode bounds"); } -- (void) testPDFImageWholeProportionalFit +- (void)testPDFImageWholeProportionalFit { const CGSize containerSize = CGSizeMake(28, 28); - - PDFImageOptions* options = [[PDFImageOptions alloc] init]; - [options setSize:containerSize]; - + + PDFImageOptions *options = [PDFImageOptions new]; + options.size = containerSize; + // Scaling up XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(28, 28), [options wholeProportionalFitForContentSize:CGSizeMake(14, 14)]), @"Wrong proportional fit"); XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(20, 14), [options wholeProportionalFitForContentSize:CGSizeMake(20, 14)]), @"Wrong proportional fit"); @@ -169,7 +169,7 @@ - (void) testPDFImageWholeProportionalFit XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(28, 14), [options wholeProportionalFitForContentSize:CGSizeMake(2, 1)]), @"Wrong proportional fit"); XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(27, 27), [options wholeProportionalFitForContentSize:CGSizeMake(3, 3)]), @"Wrong proportional fit"); XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(24, 12), [options wholeProportionalFitForContentSize:CGSizeMake(6, 3)]), @"Wrong proportional fit"); - + // Scaling down XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(28, 28), [options wholeProportionalFitForContentSize:CGSizeMake(28, 28)]), @"Wrong proportional fit"); XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(28, 28), [options wholeProportionalFitForContentSize:CGSizeMake(56, 56)]), @"Wrong proportional fit"); @@ -180,35 +180,35 @@ - (void) testPDFImageWholeProportionalFit XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(14.5, 14.5), [options wholeProportionalFitForContentSize:CGSizeMake(29, 29)]), @"Wrong proportional fit"); } -- (void) testPDFImageView +- (void)testPDFImageView { - PDFImage* image = [PDFImage imageNamed:@"3" inBundle:self.bundle]; - - PDFImageView* imageView = [[PDFImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; - + PDFImage *image = [PDFImage imageNamed:@"3" inBundle:self.bundle]; + + PDFImageView *imageView = [[PDFImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + XCTAssertNil(imageView.currentUIImage, @"No PDFImage, current UIImage should be nil"); - - [imageView setTintColor:[UIColor redColor]]; - [imageView setImage:image]; + + imageView.tintColor = [UIColor redColor]; + imageView.image = image; [self.keyWindow addSubview:imageView]; - + XCTAssertNotNil(imageView.currentUIImage, @"Has PDFImage, current UIImage should not be nil"); XCTAssertTrue(CGSizeEqualToSize(imageView.currentUIImage.size, imageView.frame.size), @"Current UIImage should be same size as PDFImageView"); - - UIImageView* privateImageView = [imageView.subviews objectAtIndex:0]; - + + UIImageView *privateImageView = imageView.subviews.firstObject; + XCTAssertNotNil(privateImageView, @"Couldn't find the private image view"); XCTAssertTrue([privateImageView isKindOfClass:[UIImageView class]], @"Couldn't find the private image view"); - + // Advance to the next run loop to allow the image view to draw it's content [self pause:0]; - + XCTAssertNotNil(privateImageView.image, @"Private image view did not load an image"); - + [imageView removeFromSuperview]; } -- (void) testPDFExtensionHandling +- (void)testPDFExtensionHandling { XCTAssertNotNil([PDFImage imageNamed:@"extension1" inBundle:self.bundle], @"Failed loading pdf image"); XCTAssertNotNil([PDFImage imageNamed:@"extension1.pdf" inBundle:self.bundle], @"Failed loading pdf image"); @@ -216,12 +216,12 @@ - (void) testPDFExtensionHandling XCTAssertNotNil([PDFImage imageNamed:@"extension3.PdF" inBundle:self.bundle], @"Failed loading pdf image"); } -- (void) testPDFBarButtonItem +- (void)testPDFBarButtonItem { - PDFImage* image = [PDFImage imageNamed:@"3" inBundle:self.bundle]; - - PDFBarButtonItem* item = [[PDFBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:nil action:nil]; - + PDFImage *image = [PDFImage imageNamed:@"3" inBundle:self.bundle]; + + PDFBarButtonItem *item = [[PDFBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:nil action:nil]; + XCTAssertNotNil(item.image, @"Bar button item should have image"); XCTAssertFalse(CGSizeEqualToSize(item.image.size, CGSizeZero), @"Bar button image should have non zero size"); } @@ -229,7 +229,7 @@ - (void) testPDFBarButtonItem #pragma mark - #pragma mark Private -- (void) pause:(NSTimeInterval) seconds +- (void)pause:(NSTimeInterval)seconds { [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:seconds]]; }