2010-12-05 43 views
2

我希望將圖像添加到單元格背景,並且從半透明單元格中我可以看到tableview的背景。如何製作半透明UITableViewCells?

從下面的話題,我知道如何做透明細胞。

UITableViewCell transparent background (including imageView/accessoryView)

我上面試過,沒有工作。但是,當我添加以下代碼:

UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 
backView.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha: .4]; 
cell.backgroundView = backView; 

此單元變成灰色,沒有任何透明度,如果我改變的代碼如下,

UIView *backView = [[UIView alloc] initWithFrame:CGRectZero]; 
backView.backgroundColor = [UIColor clearColor]; 
cell.backgroundView = backView; 

的單元變成白色,仍然沒有任何透明度。

有沒有人可以給我任何線索?

回答

0

默認情況下,視圖初始化爲不透明,所以您可能需要明確設置backView.opaque = NO;以使其以任何透明度繪製。

+0

我添加了backView.opaque = NO,但它不起作用。還有其他建議嗎? – user497032 2010-12-06 01:51:44

2

要使您的半透明透明UITableViewCells,您必須使您的UITableViewCells透明,然後將單元格的backgroundView設置爲具有半透明屬性的圖像。還將單元格的selectedBackgroundView設置爲半透明圖像,並給出選定單元格的效果。

UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 
backView.backgroundColor = [UIColor clearColor]; 
cell.text.backroundColor = [UIColor clearColor]; //if you have labels on cells.. 
cell.backgroundView = backView; 

然後用在我們的透明細胞半透明效果設置圖像..

UIImageView *cellImage = [[UIImageView alloc] init]; 
[cellImage setImage:[UIImage imageNamed: @"unselectedCellImage.png"]]; 
[cell setBackgroundView:cellImage]; 
[cellImage release]; 

然後設置用於選擇的細胞的圖像,得到選擇也之後一個半透明的效果..

UIImageView *cellImageSelection = [[UIImageView alloc] init]; 
[cellImageSelection setImage:[UIImage imageNamed: @"selectedCellImage.png"]]; 
[cell setSelectedBackgroundView:cellImageSelection]; 
[cellImageSelection release]; 

它會工作.. 乾杯..

1

你可以試試這個

UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 
backView.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha: .2]; 
cell.backgroundView = backView; 

你做錯了,你選擇1.1.1 .1是黑色您需要什麼255 255 255爲白色,不透明度你是非常高,所以它實際上是看着灰色給你黑色,不透明。希望這有助於:)