Ios 无法在矩形中获得正确的UIColor

Ios 无法在矩形中获得正确的UIColor,ios,objective-c,core-graphics,Ios,Objective C,Core Graphics,全部, 我有一段代码: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); CGContextFillRect(context, CGRectMake(0, 440, 320, 30)); 我这样称呼它: _rect

全部,

我有一段代码:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
    CGContextFillRect(context, CGRectMake(0, 440, 320, 30));
我这样称呼它:

_rectangeView = [[PopUpRectangle alloc] initWithFrame:CGRectMake(0, 538, 320, 30)];
但是它是黑色的


有人告诉我这是为什么吗

像这样更改您的着色矩形

CGContextFillRect(context, CGRectMake(0, 0, 320, 30));
使用0,0作为原点,而不是0,440

这应该行得通


在drawRect中,您处理的是视图本身的向量空间,而不是其超级视图。因此0,0是
矩形视图的左上角,而
矩形视图的高度仅为30点,但上下文填充矩形边界
y
值为440.0;超出了视图的边界。尝试将
y
值更改为0,您将看到颜色

在这种情况下,
rect
的值是多少。我怀疑你正在着色的矩形实际上不在视图的矩形内。边界!=框架等等。NVM,补充了一个答案。
DrawRect:
有人打过电话吗???在其中放置一个
NSLog()。