Iphone 如何制作半透明的UITableViewCells?
我希望将图像添加到单元格背景中,从半透明的单元格中我可以看到tableview的背景 从下面的主题,我知道如何使透明细胞 我在上面试过了,确实有效。但当我添加以下代码时:Iphone 如何制作半透明的UITableViewCells?,iphone,uitableview,transparent,Iphone,Uitableview,Transparent,我希望将图像添加到单元格背景中,从半透明的单元格中我可以看到tableview的背景 从下面的主题,我知道如何使透明细胞 我在上面试过了,确实有效。但当我添加以下代码时: UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; backView.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha: .4]; cell.b
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;
细胞变成白色,仍然没有任何透明度
有人能给我一些线索吗?视图默认初始化为不透明,因此您可能需要显式设置
backView.opaque=NO代码>以使其具有任何透明度。要使UITableViewCells半透明,必须使UITableViewCells透明,然后将单元格的背景视图设置为具有半透明属性的图像。还可以将单元格的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];
会有用的。。
干杯。你可以试试这个
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,你的不透明度非常高,所以在你看来它是灰色的,实际上它是黑色的,不透明度。希望这有帮助:)我添加了backView.opaque=NO,但它不起作用。还有其他建议吗?您是否仍将单元格的backgroundColor
设置为[UIColor clearColor]
?