gpt4 book ai didi

ios - Swift 4 backgroundColor 错误?

转载 作者:可可西里 更新时间:2023-11-01 01:14:35 25 4
gpt4 key购买 nike

我的 View 透明度有问题,尤其是 UITableView

只是为了确定。我已经有 3 年的 swift 经验,这是我第一次遇到这个问题。

所以在 apple 的文档中它说了以下内容:背景颜色 View 的背景颜色。

此属性的更改可以动画化。默认值为 nil,这会产生透明的背景颜色。”

但是当对 backgroundColortableView.backgroundColor = UIColor.clear 应用清晰颜色时,背景仍然显示为白色。

这是错误还是功能?

编辑:

tableView 不再是问题。它是 tableView 中的单元格。已经尝试过的解决方案正在清除所有 subview 的背景颜色。什么都没有改变。

编辑 29.09.17

好的,我调试了我的应用程序并得到了这个:

UICachedDeviceWhiteColor 和 cachedColor。

UICachedDeviceWhiteColor

谷歌搜索也没有帮助。

编辑 29.09.2017 当天晚些时候......

问题发生在从 swift 3 更新到 swift 4 时。我用 swift 4 做了一个新项目,但它实际上工作正常。因为这是我必须解决的问题。我会尝试一些事情并不时更新这篇文章。

最佳答案

在 UITableViewCell 和 UICollectionViewCell 中有一个名为 contentView 的属性 View 。

一个常见的错误是直接操作单元格。而是尝试操纵单元格内容 View :

Obj-c

UITableViewCell *cell = ....// get the cell

cell.backgroundColor = ... // BAD !

cell.contentView.backgroundColor = [UIColor redColor] // this is the correct way.

swift

let cell = ...
cell.contentView.backgroundColor = UIColor.red // make sure its the contentView

还有一些颜色和不透明度的细微差别:

如果您希望背景具有不透明度(即小于 100%),请确保您改变 View 的不透明度(即view. alpha = 0.5 BAD) - 改为更改颜色的不透明度值:

cell.contentView.backgroundColor = [UIColor colorWithRed:... green:... blue:... alpha:0.5];

另一个有用的技巧是暂停应用程序并按下“可视化调试”按钮。

搜索您的 View 并在检查器中检查它的属性

关于ios - Swift 4 backgroundColor 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46471447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com