ios - 为什么不能设置 cell.selectionStyle = UITableViewCellSelectionStyleBlue?

标签 ios objective-c uitableview

我看到了以下问题,但没有解释,虽然您可以简单地将 cell.SelectedStyle 设置为 UITableViewCellSelectionStyleGrayUITableViewCellSelectionStyleNone,但您可以不要将它的 selectionStyle 设置为 UITableViewCellSelectionStyleBlue

他们只是提供了一个 hack 而没有解释。我只是想知道为什么,以便更好地理解 objective-c

UITableViewCellSelectionStyleBlue is not working

ios7 UITableViewCell selectionStyle won't go back to blue

Cannot change UITableView blue highlight color

最佳答案

那你不会喜欢这个答案的。从 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/

相关文章:

android - 使用 URL 方案的 Google Pay UPI 集成 - iOS

ios - 如何在 iOS 中创建带有渐变的叠加颜色

objective-c - NSTimer 是线程安全的吗?

ios - 使用动画将 uitableview 单元移动到顶部

iphone - 强制 UIImagePickerController 以横向模式拍摄视频

ios - 合并几个物理体

objective-c - 从另一个 UIBezierPath 减去 UIBezierPath

iphone - 如何默认选择 UITableViewCell?

ios - 在事务中调用当点击 UI 搜索栏并显示键盘时

ios - 切换到横向时,Tableview 将约束更改为全屏