Я хочу создать пользовательский элемент NSMenu.
Сначала я создал представление для пункта меню, а затем я установил настраиваемый вид для пункта меню.
-(void) drawRect:(NSRect)dirtyRect
{
NSRect fullBounds = [self bounds];
fullBounds.size.height += 4;
[[NSBezierPath bezierPathWithRect:fullBounds] setClip];
[[NSColor blueColor] set];
NSRectFill( fullBounds );
}
CGFloat menuItemHeight = 32;
NSRect viewRect = NSMakeRect(0, 0, 1, menuItemHeight);
NSView *menuItemView = [[FullMenuItemView alloc] initWithFrame:viewRect];
menuItemView.autoresizingMask = NSViewWidthSizable;
NSMenuItem *unlockAllMenuItem = [[NSMenuItem alloc] initWithTitle:@"UnlockAll" action:@selector(unlockAllMenuItem_Clicked:) keyEquivalent:@""];
[unlockAllMenuItem setView:menuItemView];
unlockAllMenuItem.tag = MenuItemtagUnlockAllMenuItem;
unlockAllMenuItem.target = self;
NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
style.alignment = NSTextAlignmentCenter;
unlockAllMenuItem.attributedTitle = [[NSAttributedString alloc] initWithString:unlockAllMenuItem.title attributes:@{
NSForegroundColorAttributeName:NSColor.redColor,
NSFontAttributeName:[NSFont systemFontOfSize:14.0],
NSParagraphStyleAttributeName:style, }];
[_menu addItem:unlockAllMenuItem];
Я получаю вот так:
Название пункта меню не видно на изображении выше, как вы можете видеть.
Заранее спасибо!