CustomMenuItem *menuItem = [[CustomMenuItem alloc] initWithTitle:@"" action:@selector(openPreferences:) keyEquivalent:@""];[menuItem foo];[menuItem setTarget:self];[statusMenu insertItem:menuItem atIndex:0];[menuItem release];
而我的foo方法是:
- (voID)foo { NSVIEw *vIEw = [[NSVIEw alloc] initWithFrame:CGRectMake(5,10,100,20)]; [self setVIEw:vIEw];}
如果我删除setVIEw方法,它将突出显示。
我搜索和搜索,找不到实现/启用这种方式。
编辑
我在NSVIEw SubClass中执行了这个问题中的代码实现了突出显示:
An NSMenuItem’s view (instance of an NSView subclass) isn’t highlighting on hover
#define menuItem ([self enclosingMenuItem])- (voID) drawRect: (NSRect) rect { BOol isHighlighted = [menuItem isHighlighted]; if (isHighlighted) { [[NScolor selectedMenuItemcolor] set]; [NSBezIErPath fillRect:rect]; } else { [super drawRect: rect]; }}解决方法 如果您将视图添加到菜单项,则该视图必须自己绘制高亮。你不免费得到这个,恐怕。从 Menu Programming Topics:
总结A menu item with a vIEw does not draw its Title,state,Font,or other standard drawing attributes,and assigns drawing responsibility entirely to the vIEw.
以上是内存溢出为你收集整理的objective-c – 用自定义视图突出显示一个NSMenuItem?全部内容,希望文章能够帮你解决objective-c – 用自定义视图突出显示一个NSMenuItem?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)