Saturday, 10 September 2011

Exact style for NSMenuItem?


i'm trying nsmenuitem have exact same font/style default ones, i'm having troubles.

here's code:
code:
nsdictionary *attributedictionary = [nsdictionary dictionarywithobjectsandkeys:[nsfont fontwithname:@"lucidagrande" size:13.0], nsfontattributename, nil]; statusitem.attributedtitle = [[nsattributedstring alloc] initwithstring:[nsstring stringwithformat:@" mon feb 6"] attributes:attributedictionary];
i've attached output below. on far left menu item. on far right built in date / time menu item i'm trying copy.

it's close, not quite right. it's told proper font, looks me proper font several os versions ago (10.4?) looks little sharp... should taller , wider. making next size makes tall. making bold... actually, haven't figured out how bold (i've tried adding "-bold" end of name of font, seems result in getting unrelated font show up...)

edit: adding shadow offset of 0.5, 0.5 seems little promising... doesn't quite right, though...
 

attached files:

i played around few ideas, , seems best results. seems turning off cgcontextsetshouldsmoothfonts() makes better.

code:
[color=#5c2699]nstextfieldcell[/color] *cell = [[[[color=#5c2699]nstextfieldcell[/color] [color=#2e0d6e]alloc[/color]] [color=#2e0d6e]inittextcell[/color]:text] [color=#2e0d6e]autorelease[/color]];  [cell [color=#2e0d6e]setdrawsbackground[/color]:[color=#aa0d91]no[/color]];  [cell [color=#2e0d6e]setfont[/color]:font];  [cell [color=#2e0d6e]setbackgroundstyle[/color]:[color=#2e0d6e]nsbackgroundstyleraised[/color]];    [color=#5c2699]nssize[/color] cellsize = [cell [color=#2e0d6e]cellsize[/color]];  [color=#5c2699]nssize[/color] imgsize = [color=#2e0d6e]nsmakesize[/color]([color=#2e0d6e]floor[/color](cellsize.[color=#5c2699]width[/color]), [[[color=#5c2699]nsstatusbar[/color] [color=#2e0d6e]systemstatusbar[/color]] [color=#2e0d6e]thickness[/color]]);  [color=#5c2699]nsimage[/color] *img = [[[color=#5c2699]nsimage[/color] [color=#2e0d6e]alloc[/color]] [color=#2e0d6e]initwithsize[/color]:imgsize];  [img [color=#2e0d6e]lockfocus[/color]];  [color=#5c2699]nsrect[/color] bounds = [color=#2e0d6e]nsmakerect[/color]([color=#1c00cf]0[/color], [color=#1c00cf]0[/color], imgsize.[color=#5c2699]width[/color], imgsize.[color=#5c2699]height[/color]);  [color=#5c2699]cgcontextref[/color] ctx = ([color=#5c2699]cgcontextref[/color])[[[color=#5c2699]nsgraphicscontext[/color] [color=#2e0d6e]currentcontext[/color]] graphicsport];  [color=#2e0d6e]cgcontextsavegstate[/color](ctx);  [color=#2e0d6e]cgcontextsetshouldsmoothfonts[/color](ctx, [color=#643820]false[/color]);  [color=#5c2699]nsrect[/color] cellrect = [color=#2e0d6e]nsmakerect[/color]([color=#1c00cf]0[/color], (bounds.[color=#5c2699]size[/color].[color=#5c2699]height[/color] - cellsize.[color=#5c2699]height[/color]) / [color=#1c00cf]2[/color], cellsize.[color=#5c2699]width[/color], cellsize.[color=#5c2699]height[/color]);  [cell [color=#2e0d6e]drawwithframe[/color]:cellrect [color=#2e0d6e]inview[/color]:[color=#aa0d91]nil[/color]];  [color=#2e0d6e]cgcontextrestoregstate[/color](ctx);  [img [color=#2e0d6e]unlockfocus[/color]];    [statusitem [color=#2e0d6e]setimage[/color]:img];
 


Forums Macs Mac Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment