【发布时间】:2023-03-18 00:00:01
【问题描述】:
我正在使用带有标题和图像的 NSPopUpButton。以下是我的代码:
[self.popup addItemWithTitle:@"Parag"];
[[self.popup lastItem] setImage:[NSImage swatchWithColor:[NSColor greenColor] size:NSMakeSize(10.0, 10.0)]];
@interface NSImage (ImageAdditions)
+(NSImage *)swatchWithColor:(NSColor *)color size:(NSSize)size;
@end
@implementation NSImage (ImageAdditions)
+(NSImage *)swatchWithColor:(NSColor *)color size:(NSSize)size
{
NSImage *image = [[NSImage alloc] initWithSize:size];
[image lockFocus];
[color drawSwatchInRect:NSMakeRect(0, 0, size.width, size.height)];
[image unlockFocus];
return image;
}
@end
如果我选择弹出按钮,图像颜色会变暗:
【问题讨论】:
-
在 mojave 下正常工作
标签: objective-c macos cocoa nsmenuitem nspopupbutton