当我尝试在NSWindow对象上调用setColorSpace时,颜色没有变化。我的印象是我可以动态地改变颜色的呈现方式。
下面是我的控制器的.h文件
#import <Cocoa/Cocoa.h>
@interface MainWindow : NSWindowController <NSTextFieldDelegate>
{
}
@property (strong) IBOutlet NSWindow *theWindow;
@property (weak) IBOutlet NSTextField *RedField;
@property (weak) IBOutlet NSTextField *GreenField;
@property (weak) IBOutlet NSTextField *BlueField;
@property (weak) IBOutlet NSTextField *PatternField;
@property (weak) IBOutlet NSButton *ICCBox;
- (IBAction)UpdateICC:(id)sender;
@end下面是我的控制器的.m文件
#import "MainWindow.h"
#import <AppKit/AppKit.h>
@interface MainWindow ()
@end
@implementation MainWindow
- (id)init
{
self = [super init];
return self;
}
- (void)awakeFromNib
{
[_RedField setDelegate:self];
[_GreenField setDelegate:self];
[_BlueField setDelegate:self];
}
-(void) controlTextDidChange:(NSNotification *) note {
float redByte = [_RedField floatValue];
float redF = redByte/255.0;
float greenByte = [_GreenField floatValue];
float greenF = greenByte/255.0;
float blueByte = [_BlueField floatValue];
float blueF = blueByte/255.0;
_PatternField.backgroundColor = [NSColor colorWithCalibratedRed:redF green:greenF blue:blueF alpha:1];
}
- (IBAction)UpdateICC:(id)sender {
NSColorSpace *acs = [NSColorSpace adobeRGB1998ColorSpace];
NSColorSpace *scs = [NSColorSpace sRGBColorSpace];
NSColorSpace *dcs = [NSColorSpace deviceRGBColorSpace];
if(_ICCBox.state == NSOnState)
{
[_theWindow setColorSpace:scs];
}
else
{
[_theWindow setColorSpace:dcs];
}
}
@end你知道为什么这不管用吗?
发布于 2017-12-01 00:28:20
您应该将指定的通知张贴到默认NotificationCenter以立即应用更改(导致使用新的颜色配置文件重新绘制窗口)。
- (IBAction)UpdateICC:(id)sender {
NSColorSpace *acs = [NSColorSpace adobeRGB1998ColorSpace];
NSColorSpace *scs = [NSColorSpace sRGBColorSpace];
NSColorSpace *dcs = [NSColorSpace deviceRGBColorSpace];
if(_ICCBox.state == NSOnState)
{
[_theWindow setColorSpace:scs];
}
else
{
[_theWindow setColorSpace:dcs];
}
[[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeScreenNotification object:_theWindow];
// In some cases additional call needed:
[_theWindow.contentView viewDidChangeBackingProperties];
}https://stackoverflow.com/questions/28207130
复制相似问题