I have to implement NSMenuItem such a way that selected NSMenuItem should have Bold Text , this is what i have done,
@implementation NSMenuItem (Font)
-(void)setBoldStyle:(bool)bBold{
NSString* title = [self title] ;
NSFont *pFont = (bold)?[NSFont boldSystemFontOfSize:14]:[NSFont menuFontOfSize:12];
NSDictionary* fontAttribute = [NSDictionary dictionaryWithObjectsAndKeys:
pFont, NSFontAttributeName,
nil] ;
NSMutableAttributedString* newTitle = [[NSMutableAttributedString alloc] initWithString:title
attributes:fontAttribute] ;
[self setAttributedTitle:newTitle] ;
[newTitle release] ;
}
@end
With Above peiece of code, i am able to set the bold text when a particular NSMenuItem gets selected, but if it needs to be toggled ( Means if an item was bold earlier, it should be normal now), then its not happening,
This is the way i am calling it,
// have we selected any menuitem yet
if ( prevStatusIndex >0){
// then deselect it
pTempMenuItem = [pMenu itemAtIndex:prevStatusIndex];
[pTempMenuItem setBoldStyle:NO];
}
prevStatusIndex = clientStatus+1;
pTempMenuItem = [pMenu itemAtIndex:prevStatusIndex]; // 1 because a separator added
[pTempMenuItem setBoldStyle:YES];
Any idea whats going wrong ?