【发布时间】:2011-03-25 10:55:28
【问题描述】:
我正在尝试为分组 UITableView 中的单元格提供半透明图像作为背景。我尝试了很多不同的方法,但似乎无法让它发挥作用。这是我到目前为止所得到的:
-(void) viewWillAppear:(BOOL) animated{
[super viewWillAppear:animated];
self.table.backgroundColor = [UIColor clearColor];}
.
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UIImage *cellBackground;
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
NSInteger row = [indexPath row];
if (row == 0)
{
cellBackground = [UIImage imageNamed:@"tCT.png"];
}
else if (row == sectionRows -1)
{
cellBackground = [UIImage imageNamed:@"tableCellBottom.png"];
}
else
{
cellBackground = [UIImage imageNamed:@"tableCellMiddle.png"];
}
cell.backgroundColor = [UIColor clearColor];
UIView *cellBackView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
cellBackView.backgroundColor = [UIColor colorWithPatternImage: cellBackground];
cell.backgroundView = cellBackView;
所以现在图像显示出来了,但它的透明度并不明显。背景是纯灰色(而不是半透明灰色)。圆角组桌角上也有黑色角。
知道我哪里出错了吗?
【问题讨论】:
-
你的图片已经透明了吗?因为如果没有,你必须设置 imageView alpha。
-
图片绝对是透明的。我在 Photoshop 中创建它,为 Web&Devices 导出并勾选“透明度”。透明度在 Finder 的 QuickLook 中显示良好。
标签: iphone