Drawing text with alpha
Drawing text with alpha
- Subject: Drawing text with alpha
- From: Phil <email@hidden>
- Date: Tue, 21 Aug 2007 20:41:51 -0400
This seems to be a common question related to drawing graphics but I
haven't found an answer that addresses alpha and text. I've got a
simple NSView subclass which draws a blue background and want to draw
text with it's background alpha set to .1. But as the alpha is
decreased, the background becomes black. My example (how not to do
it) code:
- (void)drawRect:(NSRect)rect {
[[NSColor blueColor] setFill];
NSRectFill(rect);
NSColor *fg=[NSColor orangeColor],
*bg=[[NSColor whiteColor] colorWithAlphaComponent:0.1];
NSDictionary *attr = [NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:[NSFont fontWithName:@"Chalkboard" size:
18.0], fg, bg, nil]
forKeys:
[NSArray arrayWithObjects:NSFontAttributeName,
NSForegroundColorAttributeName, NSBackgroundColorAttributeName, nil]];
[@"Background test" drawAtPoint:NSMakePoint(50.0,50.0)
withAttributes:attr];
}
This problem seems pretty common to drawing newbies like myself...
any pointers to some documentation which discusses the various
drawing operations, the compositing mode(s), and alpha in detail are
appreciated. The Cocoa Drawing Guide is where I expected to find
this but other than discussing transparency and how to set it for a
color I couldn't find anything more which could lead one to
incorrectly assume it would 'just work.'
Thanks,
Phil
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden