Forked from GenjiApp/NSImage+DrawAttributedString.h
Last active
August 29, 2015 14:12
Revisions
-
GenjiApp revised this gist
Jan 13, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #import "NSImage+DrawAttributedString.h" @implementation NSImage (DrawAttributedString) -
GenjiApp created this gist
Dec 25, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ #import <AppKit/AppKit.h> @interface NSImage (DrawAttributedString) + (NSImage *)imageWithAttributedString:(NSAttributedString *)attributedString backgroundColor:(NSColor *)backgroundColor; + (NSImage *)imageWithAttributedString:(NSAttributedString *)attributedString; + (NSImage *)imageWithString:(NSString *)string; @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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #import "NSImage+Additions.h" @implementation NSImage (DrawAttributedString) + (NSImage *)imageWithAttributedString:(NSAttributedString *)attributedString backgroundColor:(NSColor *)backgroundColor { NSSize boxSize = [attributedString size]; NSRect rect = NSMakeRect(0.0, 0.0, boxSize.width, boxSize.height); NSImage *image = [[NSImage alloc] initWithSize:boxSize]; [image lockFocus]; [backgroundColor set]; NSRectFill(rect); [attributedString drawInRect:rect]; [image unlockFocus]; return [image autorelease]; } + (NSImage *)imageWithAttributedString:(NSAttributedString *)attributedString { return [self imageWithAttributedString:attributedString backgroundColor:[NSColor clearColor]]; } + (NSImage *)imageWithString:(NSString *)string { NSAttributedString *attrString = [[[NSAttributedString alloc] initWithString:string] autorelease]; return [self imageWithAttributedString:attrString]; } @end