2011-09-10 12 views
0

透明な部分を持つUIViewにUITableViewCellを追加します。最初はすべてが完璧に見えますが、行の選択を解除すると、UIViewの背景が透明になりません。UIViewの背景の透明度

ステップ1

http://img29.imageshack.us/img29/1842/screenshot20110910at409.png

ステップ2

http://img41.imageshack.us/img41/1842/screenshot20110910at409.png

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

UIView *priceView = [[UIView alloc] init]; 
priceView.frame = CGRectMake(250, 10, 40, 21); 

priceView.backgroundColor = [UIColor colorWithPatternImage:[ UIImage imageNamed:@"priceBG.png" ]]; 
priceView.opaque = NO; 
[priceView.layer setOpaque:NO]; 
[cell addSubview:priceView]; 
[priceView release]; 
return cell; 
+1

'[[セルcontentView] addSubview:priceView]試し'と何が起こるかを教えて? – deanWombourne

+0

@deanWombourneまだ動作しません – user837488

答えて

0

代わりにUIImageViewを使用してセルのcontentViewに追加します。

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

UIImageView *priceImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"priceBG.png" ]]; 
priceImageView.frame = CGRectMake(250, 10, 40, 21); 
priceImageView.backgroundColor = [UIColor clearColor]; 
[cell.contentView addSubview:priceImageView]; 
[priceImageView release];  
return cell; 
0

私はあなたの質問に答えるかどうかはわかりませんが、tableViewCellのバックグラウンドを設定するには、セルのtowプロパティをチェックしてください。

  1. backgroundView
  2. selectedBackgroundView

あなたの目的は、UIImageViewを使用すると、セル場合contentViewにサブビューとして設定し、セルに背景を与えることはない場合。

セル選択スタイルに問題があるようです。ここでselectStyleプロパティを確認してください。適切なバックグラウンドビューを割り当てると、その青色を削除するのに役立ちます。

以下は、クラス参照へのリンクです。

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html