我正在尝试通过在NSViewController
. 我正在使用此代码更改图像的颜色:
- (NSImage *)image:(NSImage *)image withColour:(NSColor *)colour
{
NSImage *img = image.copy;
[img lockFocus];
[colour set];
NSRect imageRect = NSMakeRect(0, 0, img.size.width, img.size.height);
NSRectFillUsingOperation(imageRect, NSCompositingOperationSourceAtop);
[img unlockFocus];
return img;
}
我试过从viewWillLayout
self.help1Image.image = [self image:self.help1Image.image withColour:[NSColor systemRedColor]];
但似乎系统颜色总是返回相同的 RGB 值。
我也尝试过收听通知AppleInterfaceThemeChangedNotification
,但即使在这里,RGB 值似乎也保持不变1.000000 0.231373 0.188235
。
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"AppleInterfaceThemeChangedNotification"
object:nil
queue:nil
usingBlock:^(NSNotification * _Nonnull note) {
NSLog(@"AppleInterfaceThemeChangedNotification");
self.help1Image.image = [self image:self.help1Image.image withColour:[NSColor systemRedColor]];
NSColorSpace *colorSpace = [NSColorSpace sRGBColorSpace];
NSColor *testColor = [[NSColor systemBlueColor] colorUsingColorSpace:colorSpace];
CGFloat red = [testColor redComponent];
CGFloat green = [testColor greenComponent];
CGFloat blue = [testColor blueComponent];
NSLog(@"%f %f %f", red, green, blue);
}];
我在NSButtonCell
sublass 和压倒一切的工作正常,layout
但不能让它在NSViewController