UITableViewCell Selectioncolor 隐藏所有内容
当我选择自定义单元格时,它会隐藏单元格中的所有内容并仅显示选择颜色。
如何在选择时使背景变暗一点?
When I select a custom made cell it hides everything in the cell and shows only the selection color.
how can I just darken the background a bit when selected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了重写
setHighlighted:
之外,您还可以使用表视图单元格的视图构成来发挥自己的优势。当 iOS 应用突出显示时,它实际上是使用每个表视图单元格的
selectedBackgroundView
属性。因此,您可以创建一个自定义 UIView(但是对其进行样式设置,例如为其提供所需的背景颜色)并将其设置为表视图单元格。自定义单元格的其他详细信息时,请在cellForRowAtIndexPath:
中执行此操作。这意味着您可以自己控制选择; iOS 默认渐变不会应用。
还可以通过 Interface Builder 更改
selectedBackgroundView
。在与自定义单元格相同的笔尖中,在笔尖中创建另一个视图(而不是自定义表格视图单元格的子视图),并将其与自定义表格视图单元格的“selectedBackgroundView”出口连接起来。Alternatively to overriding
setHighlighted:
, you can use the view makeup of a table view cell to your advantage.When iOS applies the highlight, it is actually using the
selectedBackgroundView
property of each table view cell. So, you can make a custom UIView (style it however, such as giving it your desired background colour) and set that as theselectedBackgroundView
property (cell.selectedBackgroundView
) of the table view cell. Do this incellForRowAtIndexPath:
, when customising the other details of your cell.This will mean you take control of the selection yourself; the iOS default gradient will not be applied.
It is also possible to change the
selectedBackgroundView
via Interface Builder. In the same nib as your custom cell, create another view in the nib - not a subview of the custom table view cell - and wire that up with the `selectedBackgroundView' outlet of the custom table view cell.如果那是自定义单元格,请实施
并调整其中的背景颜色。
If that's a custom cell, implement
And adjust the background color within it.
您可以在选择单元格时添加突出显示的文本颜色。
根据突出显示的单元格选择颜色设置选定的文本颜色。
You can just add highlighted text color when you select cell.
Set selected Text Color as per your highlighted cell selection color.