【问题标题】:Setting the default NSView fill colour using a variable使用变量设置默认的 NSView 填充颜色
【发布时间】:2012-08-01 17:54:29
【问题描述】:

我正在尝试用一种颜色填充我的NSView,但它没有使用我想要的颜色。它只是黑色的。

这是我对 NSView 子类的实现:

#import "OCOvalView.h"

@implementation OCOvalView

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        bgColorValue = [NSColor greenColor];//I WANT IT TO BE FILLED GREEN
    }

    return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
    [bgColorValue set];
    [NSBezierPath fillRect:[self bounds]];//BUT IT ENDS UP BLACK!!
}

@end

如果我将[bgColorValue set]; 更改为[[NSColor greenColor] set];,它将起作用,但我想使用如上所示的变量。

如何使填充颜色与bgColorData 的颜色相同?

【问题讨论】:

    标签: objective-c macos nsview


    【解决方案1】:

    解决方案:由于我在 initWithFrame:frame 中设置了 bgColorValue,因此在这种情况下不会调用它。我现在将变量设置为:

    -(void)awakeFromNib{
        bgColorValue = [NSColor greenColor];
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-03
      • 2016-10-05
      • 2011-03-17
      • 1970-01-01
      • 2011-07-05
      • 1970-01-01
      • 2019-01-16
      • 2011-11-24
      • 1970-01-01
      相关资源
      最近更新 更多