我看到了以下问题,但没有解释,虽然您可以简单地将 cell.SelectedStyle
设置为 UITableViewCellSelectionStyleGray
或 UITableViewCellSelectionStyleNone
,但您可以不要将它的 selectionStyle 设置为 UITableViewCellSelectionStyleBlue
。
他们只是提供了一个 hack 而没有解释。我只是想知道为什么,以便更好地理解 objective-c
UITableViewCellSelectionStyleBlue is not working
最佳答案
那你不会喜欢这个答案的。从 iOS 7 开始,设置
cell.selectionStyle = UITableViewCellselectionStyleBlue;
现在会给你灰色。苹果在 iOS 7 中去掉了它,所以现在 selectionStyleBlue 不再以蓝色存在。它是灰色的。
这是 Apple 的 UITableViewCell 类引用文档中的引述:
- Blue
The cell has a default background color when selected.
In iOS 7, the selection color is no longer blue. Use UITableViewCellSelectionStyleDefault instead.
Available in iOS 2.0 and later.
当然,我相信您已经发现了,您可以创建一个 UIView 并将其设置为背景以模拟蓝色选区。
这是该方法的链接:UITableView cell blue highlight on selection
编辑:
只是为了清楚。 UITableViewCellSelectionStyleBlue 使选择样式变灰。
没有 UITableViewCell 的默认方法使选择样式为蓝色。
为了使选择样式成为默认灰色以外的任何颜色,您必须像我提供的链接中那样创建自定义 UIView。
关于ios - 为什么不能设置 cell.selectionStyle = UITableViewCellSelectionStyleBlue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35775494/