ios - 无法使 UITableViewCell 具有清晰的颜色

标签 ios xcode uitableview

这很简单。我已经在 tableView:willDisplayCell:forRowAtIndexPath:tableView:CellForRow:atIndexPath: 中尝试了几次。

这是我的代码:

cell.alpha = 0.0
cell.backgroundView?.alpha = 0.0
cell.contentView.alpha = 0.0
cell.backgroundView?.backgroundColor = UIColor.clear
cell.backgroundColor = UIColor.clear
cell.contentView.backgroundColor = UIColor.clear

我很确定这应该是矫枉过正,但我​​真的很难完成这项工作。正在 if 语句内修改单元格,因为这仅适用于某些单元格。是的,我检查过,if 语句按预期工作。有什么想法吗?

我使用的是 Xcode 8.2 测试版

最佳答案

你应该设置:

cell.backgroundColor = .clear

你还应该为整个 tableView 提供清晰的颜色:

tableView.backgroundColor = .clear

我已经在示例项目中进行了测试。我用 UITableView 创建了 UIViewController。为 UIViewControllerview 设置 .red 颜色。创建 UITableView,为 celltableView 应用 .clear 颜色。您应该看到红色背景 - 因此单元格和 tableView 是透明的。

这是示例屏幕(标签添加到 UIViewController.view 以确保 tableView 是透明的):

enter image description here

关于ios - 无法使 UITableViewCell 具有清晰的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40577849/

相关文章:

ios - 如何在核心数据中持久化 NSMutableArray?

ios - UIScrollView 在滚动时暂停 NSTimer

ios - iPhone X - Safe Area 没有实现全面屏体验?

ios - 由于未捕获的异常 'NSRangeException' 而终止应用程序,原因 : '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array

ios - 如何知道我的 UITableView 中没有选择任何行?

ios - Alamofire:[结果]:失败:错误域=NSURLErrorDomain 代码=-999 "cancelled"

ios - 通话进行时如何管理应用程序 View ?

ios - 无法删除 tableView 中的行

ios - "Navigation bar"的警告帧在运行时会有所不同出现在 Xcode 8 Swift 3 中

iphone - 当部分为空时,分组的 UITableView 显示空白