【问题标题】:Container View White Background, iPad Swift Issue容器视图白色背景,iPad Swift 问题
【发布时间】:2015-02-24 05:01:53
【问题描述】:

我的问题只出现在 iPad 上。默认情况下,我的容器视图是清晰/透明的。它可以在 iPhone 上正常工作,但在 iPad 上显示时默认为白色背景。大多数自定义 uitableviews 上的问题也是一样的。

我已附上以下问题的图片:

【问题讨论】:

  • 感谢您为我添加图片。

标签: ios objective-c swift


【解决方案1】:

这基本上是我的问题的解决方案,我必须添加的唯一内容是使用 tableViewDelegate 的“willDisplayCell”方法。

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { var backgroundView : UIView = UIView(frame: CGRect.zeroRect) backgroundView.backgroundColor = UIColor.clearColor() cell.backgroundView = backgroundView cell.backgroundColor = UIColor.clearColor() }

【讨论】:

    【解决方案2】:

    iPad 上单元格的背景颜色有问题。我遇到过这个问题。

    我已通过将单元格所有组件的背景颜色更改为代码中的清晰颜色来解决此问题。

    //in cell's awakeFromNib
    UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
    backgroundView.userInteractionEnabled = NO;
    backgroundView.backgroundColor = [UIColor clearColor];
    self.backgroundView = backgroundView;
    
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    

    我觉得this很有帮助

    【讨论】:

    • 这基本上是我的问题的解决方案,唯一我必须添加并且我将附加快速代码的是使用 tableViewDelegate 的“willDisplayCell”方法。查看解决方案的 OP。
    • 我认为,使用 cellWillAppear 方法是很好的解决方案:)。但是我没有使用它,因为它被多次调用(每次单元格消失和出现时),并且每次 UIView 都被分配。我更喜欢为我的应用程序中的每种类型的单元格使用自定义类,并覆盖 awakeFromNib 或 initWith... 方法来配置自定义参数。
    【解决方案3】:

    单元格ContentView 的默认颜色对于iPhoneiPad 是不同的。

    您必须在情节提要中设置Background colour of Cell's ContentView,然后您就完成了。

    【讨论】:

    • 必须更改 Cell 和它的内容视图的背景颜色?
    • 我用 willDisplayCell 方法修复了它,然后从那一点开始改变。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-17
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多