Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
i've noticed that when adding attributes to a title (an NSMenuItem title in this case), if i don't specifically add an NSFontAttributeName to the attributes, the resulting attributed title will be much smaller and of different font than the other NSMenuItems.

in the code below, i would like "Stop Clock" to remain the default size and font of an NSMenuItem, while changing the remainder of the string. the closest i can get is the commented out line below, but it's still not the correct font or size. is this normal? if so, what is the default name and size of NSMenuItems?

Code:
NSMutableAttributedString *timeRemaining = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"Stop Clock - %d Remaining", [self timeMenuSelection]]];
[timeRemaining addAttribute:NSForegroundColorAttributeName value:[NSColor grayColor] range:NSMakeRange(10, ([appendedTimeRemaining length]-10))];
[COLOR="SeaGreen"]//[timeRemaining addAttribute:NSFontAttributeName value:[NSFont userFontOfSize:14] range:NSMakeRange(0, [appendedTimeRemaining length])];[/COLOR] 
[MainMenu_Item3 setAttributedTitle:timeRemaining];

perhaps it's possible to append the new attributed title to "Stop Clock" with something like the following? (something like meaning this code doesn't work).

Code:
[MainMenu_Item3 setAttributedTitle:[NSString stringWithFormat:@"Stop Clock %@", timeRemaining]];
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
You could try a few things. First get the existing attributedTitle and make a mutableCopy of that and work with that. Second you could create a new one from scratch and get the font via [NSFont menuFontOfSize:]
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
thanks... menuFontOfSize:14 seems to refer to the default... i actually measured it in photoshop since it's not terribly obvious between fonts 14 and 15 on my screen. :eek:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.