2012-01-03 138 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]; 
}