Search code examples
objective-cmacoscocoansmenuitem

NSMenuItem setTitle with columns


I want to set a title like

Name:________Rank:

blbalb_______5

aksjdnaas____6

123123123..._7

q____________8

Assume that _ = blank

Is it possible ? If so can someone guide me how ?

I tried to do it this way

- (NSString *)getFromatedAppDescription
{
//    NSMutableString * formatedString = [[NSMutableString alloc]init];

    NSString * name = _userName;
    if ([name length] > MAX_NAME_LENGTH)
    {
        name = [NSString stringWithFormat:@"%@...",[name substringToIndex: MAX_NAME_LENGTH - 3]];//Truncate Tail
    }

    return [NSString stringWithFormat:@"%-15s %d",[name UTF8String],_rank];
}

But it fails :(

EDIT:

I solved it by creating NSView and adding there NSTextFields But I ended up with 5 NSTExtFields And I doubt it is inefficient solution :-( I would still like to see some tips from people here because I eager to improve the performance as much as I can


Solution

  • You can achieve this by setting the font of your text to a Monospaced font, see the Monospaced font on Wikipedia.