Replicating Apples embossed text in a Cocoa App
[update] Thanks to the chaps below in the comments, my in-experience with cocoa is shown. This whole post could be replaced with this code:
[[myTextField cell] setBackgroundStyle:NSBackgroundStyleRaised];
If you look at the text in the task or status bar on of a Mac app, you will see that the text has the appearance of being embossed slightly. It is essentially a textField with some neat attributes associated with it.
This effect does not come for free when you want to use your own NSTextField somewhere else in your Apps window (actually, I think it does on the iPhone?). To recreate this effect is quite simple. You just need to create a NSAttibutedString and associate the attributes below to it.
// Create the white shadow that sits behind the text NSShadow *shadow = [[NSShadow alloc] init]; [shadow setShadowColor:[NSColor colorWithDeviceWhite:1.0 alpha:0.5]]; [shadow setShadowOffset:NSMakeSize(1.0, -1.1)]; // Create the attributes dictionary, you can change the font size // to whatever is useful to you NSMutableDictionary *sAttribs = [[[NSMutableDictionary alloc] initWithObjectsAndKeys: [NSFont systemFontOfSize:11.0],NSFontAttributeName, shadow, NSShadowAttributeName, nil] autorelease]; // The shadow object has been assigned to the dictionary, so release [shadow release]; // Create a new attributed string with your attributes dictionary attached NSAttributedString *s = [[NSAttributedString alloc] initWithString:@"82 results found" attributes:sAttribs]; // Set your text value [myTextField setAttributedStringValue:s]; // Clean up [s release];
I’m sure there are many other ways to achieve this effect, and I’d be interested in any easier versions, but this works for me.