Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 9e9f6f2743
Fetching contributors…

Cannot retrieve contributors at this time

44 lines (36 sloc) 1.15 kB
//
// UIImage+BBlock.m
// BBlock
//
// Created by David Keegan on 3/21/12.
// Copyright (c) 2012 David Keegan. All rights reserved.
//
#import "UIImage+BBlock.h"
@interface UIImage(BBlockPrivate)
+ (NSCache *)drawingCache;
@end
@implementation UIImage(BBlock)
+ (NSCache *)drawingCache{
static NSCache *cache = nil;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
cache = [[NSCache alloc] init];
});
return cache;
}
+ (UIImage *)imageForSize:(CGSize)size withDrawingBlock:(void(^)())drawingBlock{
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);
drawingBlock();
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
+ (UIImage *)imageWithIdentifier:(NSString *)identifier forSize:(CGSize)size andDrawingBlock:(void(^)())drawingBlock{
UIImage *image = [[[self class] drawingCache] objectForKey:identifier];
if(image == nil){
image = [[self class] imageForSize:size withDrawingBlock:drawingBlock];
[[[self class] drawingCache] setObject:image forKey:identifier];
}
return image;
}
@end
Jump to Line
Something went wrong with that request. Please try again.