0

我目前正在尝试为具有负边界原点的 NSView 设置背景颜色/图案。问题是,它只为视图的部分着色(x>0 && y>0 的部分)。

我明白,我必须在 -(void)drawRect: 函数中绘制背景。如何为整个视图着色,而不仅仅是坐标为正的那些部分?

NSView 原点:-65、-65 尺寸:130、130

我想给整个背景上色

4

1 回答 1

0

尝试使用NSBezierPath对象来设置视图的背景颜色:

NSColor *color; //your background colour
CustomView *view; //this is your view, you should init it with the his own class
[color set];
[NSBezierPath fillRect:[view bounds]]; //sets the given Rect with the set colour

此代码应使用给定颜色为所有背景着色。[path fillRect:[self bounds]]请注意,如果代码在视图类的实现中,则应将最后一行替换为。

于 2013-03-17T18:49:56.253 回答