表视图单元格内的 UIImage
在每个单元格的表格视图中,我都有一个图像以及一些文本和其他内容。当我选择一个单元格时,我希望图像也被蓝色覆盖层覆盖。现在,除图像之外的所有其他内容都被选中,并且蓝色覆盖层覆盖了单元格。
如何实现这一目标?
Inside my table view for each cell I have an image along with some text and other stuff. When I select a cell I want the image also to be covered with blue overlay. Right now all other stuff excluding image is getting selected and a blue overlay covers the cell.
How to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将无法用蓝色覆盖层来覆盖您的图像。蓝色渐变是单元格的背景视图,而您的 UIImage 要么在 contentView 内绘制,要么作为子视图添加到其中。
一种可能的解决方法是在整个单元格顶部添加一个 CALayer,以模仿默认的蓝色背景。
You won't be able to have that blue overlay to cover your image. The blue gradient is the backgroundView of the cell, whereas your UIImage is either drawn inside the contentView or added to it as a subview.
A possible workaround would be to add a CALayer on top of the whole cell that would mimic the default blue background.
似乎应该有一种方法可以在不修改图像的情况下执行此操作,但到目前为止我能找到的只是在选择单元格时指定新图像。 UIImageView 有
image
和highlightedImage
的属性,因此您似乎需要提供自己的图像以在选择单元格时使用,因此您需要设置 <代码>cell.imageView.image和cell.imageView.highlightedImage
。Sam 的解决方法也是一个不错的方法。特别是如果您不想提供自己的图像
It seems like there should be a way to do this without modifying your image, but all I can find so far is to specify a new image when the cell is selected. UIImageView has a property for both
image
andhighlightedImage
, so it would seem you need to provide your own image to use when the cell is selected, so you would need to setcell.imageView.image
andcell.imageView.highlightedImage
.Sam's workaround would be a good approach, also. Especially if you don't want to provide your own image