Last active
December 16, 2015 09:38
-
-
Save epologee/5413892 to your computer and use it in GitHub Desktop.
This file contains 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
[UIImage tttImageWithSize:CGSizeMake(44, 44) | |
drawing:^(CGContextRef ctx, CGSize size) { | |
UIColor *blue = [UIColor blueColor]; | |
CGContextSetFillColorWithColor(ctx, blue.CGColor); | |
CGFloat half = size.height / 2; | |
rect = (CGRect){{0, half}, {size.width, half}}; | |
CGContextFillRect(ctx, rect); | |
}]; |
This file contains 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
#import <Foundation/Foundation.h> | |
#import <UIKit/UIKit.h> | |
typedef void (^TTTDrawingBlock)(CGContextRef ctx, CGSize size); | |
@interface UIImage (TTTDrawing) | |
+ (UIImage *)tttImageWithSize:(CGSize)size drawing:(TTTDrawingBlock)drawing; | |
@end |
This file contains 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
#import "UIImage+TTTDrawing.h" | |
@implementation UIImage (TTTDrawing) | |
+ (UIImage *)tttImageWithSize:(CGSize)size drawing:(TTTDrawingBlock)drawing | |
{ | |
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
drawing(context, size); | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment