【问题标题】:How to make a UITableView as transparent one?如何使 UITableView 成为透明的?
【发布时间】:2011-09-13 12:05:05
【问题描述】:

在我的应用程序中,我针对特定场景向用户展示了一个 UITableViewController 类(分组样式)。我只想显示表格视图的单元格。背景应该是透明的,以便用户可以看到上一页。

我在表格视图控制器的viewDidLoad 方法中尝试了以下代码。但他们不工作..

self.tableView.backgroundColor = [UIColor clearColor];

self.tableView.opaque = NO;

self.tableView.backgroundView = nil;

是否可以用暗色背景显示单元格?

提前致谢

【问题讨论】:

  • 背景变暗是什么意思?浅灰色还是什么的?
  • 我不明白你在 tableview 的背景上向用户显示上一页是什么意思!!
  • 我想要类似 [link] (google.co.in/…) 的背景

标签: iphone uitableview opacity background-color


【解决方案1】:

我使用:(在 viewDidLoad 中)

   self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.opaque = NO;

然后在 cellForRowAtIndexPath:

cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:.55];

不确定这是否是您想要的,但它让您可以选择让一切变得清晰。 (显然 alpha 会因您的情况而改变,但这会衡量细胞的速度)

【讨论】:

  • 感谢您的回复。更改 Alpha 值只会影响单元格的背景。我在询问表格视图的背景透明度。当您以模态方式呈现视图/表格视图时,self.tableView.backgroundColor = [UIColor clearColor]; 行或为self.tableView 设置 alpha 值不起作用。 :(
  • 所以你希望背景是前一页,比如 50% 的 alpha,让它有“弹出”的效果?
  • this? 怎么样。代码类似于: UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; backView.backgroundColor = [UIColor clearColor]; cell.backgroundView = backView;
【解决方案2】:

仅仅改变 tableView 并没有帮助。你也必须弄乱细胞。在 cellForRowAtIndexPath:(NSIndexPath *)indexPath 方法中,将其放在 return 语句之前:

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

【讨论】:

  • 使用您的代码只是隐藏单元格。但我想降低 UITableView 的背景的不透明度
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多