iphone - 如何制作半透明的UITableViewCells?

标签 iphone uitableview transparent

我希望将图像添加到单元格背景中,并且从半透明单元格中我可以看到表格 View 的背景。

通过以下主题,我知道如何制作透明单元格。

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;

细胞变成白色,仍然没有任何透明度。

有没有人可以给我一些线索?

最佳答案

要使 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];

一定会成功的.. 干杯..

关于iphone - 如何制作半透明的UITableViewCells?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4361002/

相关文章:

iphone - NSMutableArray -removeObject : also remove a NSString if it has a different memory adress? 会吗

iphone - XCode - 多个目标,多个*国际化*名称?

ios - 访问 UIViewController 类别中的 UIButton

ios - 无效的产品标识符 : How do I verify iOS sandbox environment

ios - 不调用 ObjC 类方法。 GDB玩游戏?

ios - IOS7如何让UITableView透明化?

iOS swift : Getting repeated value while updating 2D Array in custom UITableView cell

objective-c - 空白的第一个 UITableView 部分标题

android - 以编程方式使颜色更透明

html - 翻转图像下方有不需要的灰色条