迅捷的iPad表视图不透明 [英] swift iPad Table View not Transparent

查看:117
本文介绍了迅捷的iPad表视图不透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在swift中,我有一个UI表视图,我将背景设置为透明背景清晰,而对于iPhone,它可以完美运行。但对于iPad,它没有,它有白色背景,不清楚。我看到了一个答案,但它不是迅速的,但这也不起作用。
我的iPhone代码是:

In swift, I have a UI Table View and I have the background set as clear for a transparent background, and for the iPhone it works perfectly. But for iPad, it does not, it has a white background, not clear. I saw an answer, but it wasn't for swift, but that didn't work either. My code for the iPhone is:

tableview.backgroundcolor = UIColor.clearcolor()

我尝试添加:

tableview.background = nil 

但这不起作用。

推荐答案

我遇到了同样的问题。似乎在向窗口添加UITableView的过程中的某个地方(在willMoveToWindow和didMoveToWindow之间),某些iPad将表视图的backgroundColor重置为白色。它隐蔽地执行此操作而不使用backgroundColor属性。

I ran into the same problem. It seems that somewhere in the process of adding a UITableView to the window (between willMoveToWindow and didMoveToWindow), some iPad's reset the backgroundColor of the table view to white. It does this covertly without using the backgroundColor property.

当我需要彩色/透明表时,我现在用它作为基类代替UITableView ...

I now use this as a base class in place of UITableView when I need a colored/transparent table...

class ColorableTableView : UITableView {
    var _backgroundColor:UIColor?
    override var backgroundColor:UIColor? {
        didSet {
            _backgroundColor = backgroundColor
        }
    }
    override func didMoveToWindow() {
        backgroundColor = _backgroundColor
        super.didMoveToWindow()
    }
}

编辑:单元格的backgroundColor设置为白色我的iPad也是以同样的方式(即移动到窗口期间在桌面上的那些),所以这同样适用于它们,以免最终出现奇怪的不透明单元格,因为它被重复使用。 。

Cells also have their backgroundColor's set to white on my iPad in the same way (i.e. those that are in the table during the move to the window), so the same applies to them, lest you end up with the odd opaque cell popping up from time to time as it is reused ...

class ColorableTableViewCell : UITableViewCell {
    var _backgroundColor:UIColor?
    override var backgroundColor:UIColor? {
        didSet {
            _backgroundColor = backgroundColor
        }
    }
    override func didMoveToWindow() {
        backgroundColor = _backgroundColor
        super.didMoveToWindow()
    }
}

这篇关于迅捷的iPad表视图不透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆