带有UITableViewCell的CGContextRef

时间:2011-06-11 00:23:32

标签: iphone objective-c

我有一个UIButton的子类,它使用CGContextRef绘制动态创建高亮状态背景图像。当我将按钮放在UIView中时,突出显示很好。当我将按钮放在UITableViewCell内时,高亮显示不会显示。我认为它与CGContextRef有关,因为当我用主包中的图像替换CGContextRef输出的图像时,它工作正常。在UITableViewCell中使用CGContextRef时是否需要特殊的东西?

这是我的UIButton子类的initWithFrame中的CGContextRef代码:

    //HighlightImage
    //*************************
    UIGraphicsBeginImageContext(CGSizeMake(bRect.size.width, bRect.size.height));   

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(context, 0, 1.0, 0, 1.0);
    CGMutablePathRef path = AKCGRoundedRectCreate(  CGRectOffset(bRect, 0, -bRect.origin.y), kCornerRadius);
    CGContextAddPath(context,path);
    CGPathRelease(path);

    CGContextFillPath(context);

    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    [self setBackgroundImage: resultingImage forState:UIControlStateHighlighted];
    //[self setBackgroundImage:[UIImage imageNamed:@"mainBundleImage.jpg"] forState:UIControlStateHighlighted];

0 个答案:

没有答案