2012-01-03 22 views
0

私はtableviewの背景をクリアしました。透明な背景を持つPNG画像を作成し、tableViewHeaderのbackgroundViewとして設定しました。tableViewheader透明な背景が黒くなる

何とかして、PNGの透明な背景がtableViewHeaderで黒くなります。誰か手掛かりはありますか?

ありがとうございます。

//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

私はあなたのコードを試してみて、私にとってはうまく機能します。もう一度テーブルビューを確認してください。問題がまだ見える場合は、それをもう一度クリーンアップ(shift + commond + K)してコンパイルするか、イメージをもう一度確認してください。 FInalオプションをもう一度あなたのテーブルビューをクリアします。代わりに+colorWithPatternImageがあなたのイメージにheaderViewのバッキングCALayercontentsを設定してみてください使用の

tableView.backgroundColor = [UIColor clearColor]; 
0

。この方法では、<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]; 
}