Uiview 在代码中创建的UItabaritem映像不’;不出现

Uiview 在代码中创建的UItabaritem映像不’;不出现,uiview,ios7,core-graphics,drawrect,uitabbaritem,Uiview,Ios7,Core Graphics,Drawrect,Uitabbaritem,我在代码中创建了以下视图,目的是将其用作UITableViewCell和uitabaritem中的图像: - (void)drawRect:(CGRect)rect { // Fill the background with white CGContextRef context = UIGraphicsGetCurrentContext(); UIColor * whiteColor = [UIColor colorWithRed:1.0

我在代码中创建了以下视图,目的是将其用作
UITableViewCell
uitabaritem
中的图像:

- (void)drawRect:(CGRect)rect
{
    // Fill the background with white
    CGContextRef context = UIGraphicsGetCurrentContext();

    UIColor * whiteColor = [UIColor colorWithRed:1.0
                                           green:1.0
                                            blue:1.0
                                           alpha:1.0];

    CGContextSetFillColorWithColor(context, whiteColor.CGColor);
    CGContextFillRect(context, self.bounds);

    //// Color Declarations
    UIColor* fillColor = [UIColor colorWithRed: 1.0
                                         green: 1.0
                                          blue: 1.0
                                         alpha: 1.0];

    UIColor* strokeColor = [UIColor colorWithRed: 0.0
                                           green: 0.0
                                            blue: 0.0
                                           alpha: 1.0];

    //// Big Oval Drawing
    CGRect bigOvalRect = CGRectMake(rect.origin.x+2,
                                    rect.origin.y+5,
                                    42.0,
                                    42.0);

    UIBezierPath* bigOvalPath = [UIBezierPath bezierPath];

    [bigOvalPath addArcWithCenter: CGPointMake(CGRectGetMidX(bigOvalRect), CGRectGetMidY(bigOvalRect))
                         radius: CGRectGetWidth(bigOvalRect) / 2
                     startAngle: 40 * M_PI/180
                       endAngle: 320 * M_PI/180
                      clockwise: YES];

    [fillColor setFill];
    [bigOvalPath fill];
    [strokeColor setStroke];
    bigOvalPath.lineWidth = 1;
    [bigOvalPath stroke];

 }
要从此UIView创建UIImage,我使用以下代码:

#import <QuartzCore/QuartzCore.h>

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;
}

我想这与图像的alpha有关,但我如何修复它呢?

这不是视图大小的问题,而是alpha的问题

我通过将backgroundColor(为whiteColor)和fillColor设置为:

[UIColor clearColor]
通过在
initWithFrame:
方法中将视图设置为不透明:

[self setOpaque = NO];

尝试使用
self.navigationController.tabBarItem.image=tabImage处的断点在控制台中预览图像。如果可以看到图像,则选项卡栏中的蓝色可能是由于图像大小所致。尝试使用大小等于或小于
48 x 32
尺寸的图像。
[self setOpaque = NO];