关于这个话题,我读过多次问答,但似乎都没有用,所以我的问题是。
我创建了一个定制的UITableViewCell,在故事板中,我要求有一个信息披露指示器附件。据说tintColor应该改变指示器的颜色,但是经过大量的研究,我发现:
我试图像这样用一个accessoryView创建selectedBackgroundView:
self.accessoryView = UIView()显然,它只是创造了一个空白和原来的披露附件消失。我对所有这些都很困惑,无法找到影响细胞附件颜色的方法。任何帮助都是非常欢迎的!
发布于 2015-01-15 19:35:40
以下是帮助我和应该帮助其他人的东西。
任何tintColor类型和子类型的UIView属性都会将其tint设置传播到其层次结构中的子视图。您可以将tintColor设置为UITableView,并将其应用于内部的所有单元格。
这就是说,并不是所有的UITableViewCell附件类型都能不幸地被着色。
染了色的人:
以下内容没有着色:
因此,一般来说,您将能够更改您的UITableViewCell附件的颜色。但是,如果你想改变灰色箭头,通常指示一个圣格到另一个视图,没有机会,它将保持灰色。
更改它的唯一方法是实际创建一个自定义UIAccessoryView。这里有一个有目的地分解的实现来保持它的清晰性。虽然我相信还有更好的方法:
在我的自定义UITableViewCell类中的awakeFromNib()方法中
let disclosureImage = UIImage(named: "Disclosure Image")
let disclosureView = UIImageView(image: disclosureImage)
disclosureView.frame = CGRectMake(0, 0, 25, 25)
self.accessoryView = disclosureView请注意,这也不能着色。它将具有与"Tab项“相比所使用的图像的颜色,因此您可能需要多个选定单元格和未选定单元格的图像。
发布于 2016-03-21 23:37:18
扩展
extension UITableViewCell {
func prepareDisclosureIndicator() {
for case let button as UIButton in subviews {
let image = button.backgroundImageForState(.Normal)?.imageWithRenderingMode(.AlwaysTemplate)
button.setBackgroundImage(image, forState: .Normal)
}
}
}Swift 3 :
extension UITableViewCell {
func prepareDisclosureIndicator() {
for case let button as UIButton in subviews {
let image = button.backgroundImage(for: .normal)?.withRenderingMode(.
alwaysTemplate)
button.setBackgroundImage(image, for: .normal)
}
}
}去做吧
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.prepareDisclosureIndicator()
}斯威夫特3 :
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.prepareDisclosureIndicator()
}目标-C:
for (UIView *subview in cell.subviews) {
if ([subview isMemberOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
UIImage *image = [[button backgroundImageForState:UIControlStateNormal] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[button setBackgroundImage:image forState:UIControlStateNormal];
}
}发布于 2021-03-09 04:02:41
下面是东京都大学对我们恐龙的回答的目标-C版本:
UIImageSymbolConfiguration *configuration = [UIImageSymbolConfiguration configurationWithPointSize:15.0f weight:UIImageSymbolWeightUnspecified];
UIImageView *disclosureView = [[UIImageView alloc] initWithImage:[[UIImage systemImageNamed:@"chevron.right" withConfiguration:configuration] imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate]];
disclosureView.frame = CGRectMake(0, 0, 15, 15);
disclosureView.tintColor = UIColor.systemYellowColor;
cell.accessoryView = disclosureView;您可以使用名为:"chevron.right“的系统映像来避免创建自己的系统映像。这里给出的帧大小似乎给出了一个与本地Apple图像大小相近的图像。
另外,对于要使用标准附件类型的其他单元格,请注意将cell.accessoryView设置为零。
cell.accessoryType = self.somePreference ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
cell.accessoryView = nil;https://stackoverflow.com/questions/27955447
复制相似问题