【问题标题】:Grouped UITableViewCell with transparent background image具有透明背景图像的分组 UITableViewCell
【发布时间】: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


【解决方案1】:

将单元格的 contentViewbackgroundColor 设置为 clearColor 以移除黑色边框。

self.contentView.backgroundColor = [UIColor clearColor];

【讨论】:

  • 我将它设置为 cell.contentView.backgroundColor = [UIColor clearColor];但仍然没有运气。
  • 我认为黑色边框可能归结为这一点: UIView *cellBackView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];我不熟悉以编程方式创建视图,但我假设这段代码正在创建一个矩形视图,即没有圆角的视图?
猜你喜欢
  • 2012-05-26
  • 2015-05-15
  • 2014-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-03
  • 1970-01-01
相关资源
最近更新 更多