UITableViewCell配件没有着色 [英] UITableViewCell accessory not being tinted

查看:154
本文介绍了UITableViewCell配件没有着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了关于该主题的多个Q& A,但似乎没有工作,所以这是我的问题。

I've read multiple Q&A on the topic but none seem to work so here's my problem.

我创建了一个自定义UITableViewCell并在故事板中,我要求有披露指示器附件。据说tintColor应该改变指示器的颜色,但经过大量研究后,我发现了这个:

I created a custom UITableViewCell and in the Storyboard, I asked for there to be a disclosure indicator accessory. It is said that the tintColor should change the color of the indicator but after much research, here is what I found:


  • 单元格的accessoryView地图out为零值因此我不能影响它的tintColor

我尝试用这样的selectedBackgroundView创建accessoryView:

I tried to create the accessoryView as done with a selectedBackgroundView like such:

self.accessoryView = UIView()

显然,它只会创建一个空白区域,原始的公开配件会消失。我真的很困惑这一切,无法找到影响细胞配件颜色的方法。任何帮助都会受到欢迎!

Obviously, it just creates a blank space and the original disclosure accessory disappears. I'm really confused with all this and cannot find a way to affect the color of a cell's accessory. Any help would be much welcome!

推荐答案

这对我有所帮助,应该帮助他人。

Here is what helped me and should help others.

任何UIView类型和子类型的tintColor属性都会将其色调设置传播到其层次结构中的子视图。您可以为UITableView设置tintColor,它将应用于其中的所有单元格。

The tintColor attribute of any UIView type and subtypes will propagate it's tint setting to the subviews in it's hierarchy. You could set the tintColor for a UITableView and it would be applied to all the cells within.

这表示并非所有UITableViewCell附件类型都可能会被着色。

That said not all UITableViewCell Accessory types can unfortunately be tinted.

那些染色的人:


  • UITableViewCellAccessoryCheckmark

  • UITableViewCellAccessoryDe​​tailButton

  • UITableViewCellAccessoryDe​​tailDisclosureButton - >只有详细信息部分

以下内容没有染色:


  • UITableViewCellAccessoryDisclosureIndicator

  • UITableViewCellAccessoryDe​​tailDisclosureButton - >仅披露按钮

通常,您将能够更改UITableViewCell附件的颜色。但是如果你想将通常表示segue的灰色箭头更改为另一个视图,则没有机会,它将保持灰色。

So generally, you'll be able to change the color of your UITableViewCell Accessories. But if you want to change the grey arrow that usually indicates a segue to another view, no chance, it will stay grey.

改变它的唯一方法是实际创建自定义UIAccessoryView。
这是一个有目的地细分的实现,以保持清晰。
虽然我相信存在更好的方法:

The only way to change it is to actually create a custom UIAccessoryView. Here is one implementation purposefully broken down to keep it clear. Although I believe better ways exist:

在我的awakeFromNib()方法中的自定义UITableViewCell类

In my custom UITableViewCell Class in the awakeFromNib() method

let disclosureImage = UIImage(named: "Disclosure Image")
let disclosureView = UIImageView(image: disclosureImage)
disclosureView.frame = CGRectMake(0, 0, 25, 25)
self.accessoryView = disclosureView

请注意,这也不能着色。与Tab Bar Items相比,它将使用所用图像的颜色,因此您可能需要为所选单元格和未选择单元格显示多个图像。

Be warned that this cannot be tinted either. It will have the color of the image used compared to "Tab Bar Items" so you might need multiple images for selected cells and unselected ones.

这篇关于UITableViewCell配件没有着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆