0

我无法从情节提要中绘制 UILabel;它总是空白的。标签被定义为一个属性 self.rainbowCircle。这是我的视图控制器中的设置:

self.rainbowCircle.layer.name = @"Rainbow Layer";
self.rainbowCircle.layer.delegate = self;
[self.rainbowCircle.layer setNeedsDisplay];

这是drawLayer:inContext:

- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
    CGContextSaveGState(ctx);
    if ([layer.name isEqualToString:@"Rainbow Layer"]) {
        NSLog(@"here");
        NSArray *rainbowColorsArray = [NSArray arrayWithObjects:
                                       (id)[UIColor colorWithHue:0.0                 saturation:1.0 brightness:1.0 alpha:1.0].CGColor,
                                       (id)[UIColor colorWithHue:1.0*360.0/6.0/360.0 saturation:1.0 brightness:1.0 alpha:1.0].CGColor,
                                       (id)[UIColor colorWithHue:2.0*360.0/6.0/360.0 saturation:1.0 brightness:1.0 alpha:1.0].CGColor,
                                       (id)[UIColor colorWithHue:3.0*360.0/6.0/360.0 saturation:1.0 brightness:1.0 alpha:1.0].CGColor,
                                       (id)[UIColor colorWithHue:4.0*360.0/6.0/360.0 saturation:1.0 brightness:1.0 alpha:1.0].CGColor,
                                       (id)[UIColor colorWithHue:5.0*360.0/6.0/360.0 saturation:1.0 brightness:1.0 alpha:1.0].CGColor,
                                       (id)[UIColor colorWithHue:1.0                 saturation:1.0 brightness:1.0 alpha:1.0].CGColor,
                                       nil];
        CGColorSpaceRef deviceRGB = CGColorSpaceCreateDeviceRGB();
        CGGradientRef gradient    = CGGradientCreateWithColors(deviceRGB, (__bridge CFArrayRef) (rainbowColorsArray), NULL);
        CGContextDrawRadialGradient(ctx, gradient, self.rainbowCircle.center, 0.0, self.rainbowCircle.center, self.rainbowCircle.bounds.size.width/2.0, kCGGradientDrawsBeforeStartLocation);
        CGColorSpaceRelease(deviceRGB);
        CGGradientRelease(gradient);
    } else {
        [self drawPalette:self.currentPalette inLayer:layer inContext:ctx];
    }
    CGContextRestoreGState(ctx);
}

我已经盯着这个看了很长一段时间,只是看不到我错过了什么。NSLog 确实显示。任何指导表示赞赏。

4

1 回答 1

3

您不能更改 UIView 层的委托,它必须是视图本身

于 2013-06-01T21:20:04.067 回答