2012-01-03 94 views
0

我已经清除了tableview的背景。现在我创建了一个具有透明背景的PNG图像,并将其设置为tableViewHeader的backgroundView。tableViewheader透明背景变成黑色

不知何故,在tableViewHeader中PNG的tranparent背景变成黑色。有人有任何线索怎么样?

谢谢。

//Header Layout 
UIView *headerView = 
[[[UIView alloc] 
    initWithFrame:CGRectMake(0, 0, 300, 70)] 
autorelease]; 
UILabel *headerLabel = 
[[[UILabel alloc] 
    initWithFrame:CGRectMake(10, 10, 300, 40)] 
autorelease]; 
headerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"headerBG.png"]]; 
headerLabel.text = NSLocalizedString(@"Huidig", @""); 
headerLabel.textColor = [UIColor redColor]; 
headerLabel.shadowColor = [UIColor greenColor]; 
headerLabel.shadowOffset = CGSizeMake(0, 1); 
headerLabel.font = [UIFont boldSystemFontOfSize:22]; 
headerLabel.backgroundColor = [UIColor clearColor]; 
[headerView addSubview:headerLabel]; 
tableView.tableHeaderView = headerView; 

回答

0

我试过你的代码,对我来说绝对正常。请再次检查你的tableview。如果您仍然看到问题,请清理(shift + commond + K)并再次编译一遍或再次检查您的映像。 FInal选项可以再次清除桌面视图。

tableView.backgroundColor = [UIColor clearColor]; 
0

而不是使用+colorWithPatternImage尝试headerView的后盾CALayercontents设置为你的形象。您需要链接并导入<QuartzCore/QuartzCore.h>这种方法。

headerView.layer.contents = [UIImage imageNamed:@"headerBG"].CGImage; 
1

你试过

[tableView setBackgroundColor:[UIColor clearColor]]; 
[tableView setBackgroundView:nil]; 
0

试过了???

[tableView setBackgroundColor:[UIColor clearColor]]; 
[tableView setBackgroundView:nil]; 

,并在您

-(void)viewDidAppear{ 
.................... 
.................... 
[tableview reloadData]; 
} 

可能是将现在的工作。

0

我使用[UIColor colorWithPatternImage:]为UILabel创建背景图像时遇到了类似的问题。运行4.2.1(iPhone 3G)的设备将图像的透明部分显示为黑色。我试图改变不透明的属性,并将图像设置到图层,但都没有工作。

相反,我实现了一个新的类继承的UILabel,并在我的drawRect刚刚绘制图像:

- (void)drawRect:(CGRect)rect 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextClearRect(context, rect); 

    UIImage *image = [UIImage imageNamed:@"graphics/pricetag.png"]; 
    CGContextDrawImage(context, rect, image.CGImage); 
    // Have UILabel draw the text 
    [super drawRect:rect]; 
}