1

いくつかの投稿を検索して、動的に生成されたセルの背景を透明に設定することに成功しませんでした。

ストーリーボードにはプロトタイプ テーブルがあり、その下にイメージがあります。ストーリーボードでは、プロトタイプ テーブルのアルファを 0.3 に設定して、画像が部分的に見えるようにしました。希望どおりにレンダリングされます。

問題は、セルが余分な色のレイヤーを追加するため、画像はまだ表示されますが、少し少なくなります (たとえば、アルファが 0.6 であるかのように)。実際には、3 つのレイヤーがあるようです。テーブル、セル (背景を少し暗くする)、テキストの周りの各行内の別の小さな四角形 (背景をさらに暗くする)。

セルを生成する関数を次のように編集しました (このトピックに関するスレッドから理解した内容に基づいて):

NSString *cellIdentifier = @"ItemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

cell.textLabel.text = [self.labels objectAtIndex:indexPath.row]; // gets the text of the cell from an array
cell.textLabel.textColor = [UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.0];
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
// I've also trued with  = [UIColor colorWithRed:0. green:0 blue:0 alpha:0.0] 
cell.backgroundView = backView;

問題は、私がまだその余分なレイヤーを取得していることです.

4

2 に答える 2

1

ほら、私はあなたのコードのどこかで変更を行い、それを使用しようとしました。

[tableView setOpaque:NO];

NSString *cellIdentifier = @"ItemCell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//if cell is already created then reuse it no need to create unnecessarily.
if(cell= nil){//otherwise create new cells.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle  reuseIdentifier:cellIdentifier];
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;

  }

cell.textLabel.text = [self.labels objectAtIndex:indexPath.row]; 
cell.textLabel.textColor = [UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.0];
于 2013-05-04T18:50:31.877 に答える
0
[tableView setOpaque:NO];
[tableView setBackgroundColor:[UIColor clearColor]];
于 2013-05-04T18:15:57.003 に答える