问题
I'd like to change the color of my cell accessoryType from blue to white. The textColor is already set to white. Does someone of you guys know how to do this?
My Code:
cell!.accessoryType = UITableViewCellAccessoryType.Checkmark
回答1:
You can set your UITableViewCell tintColor property to the desired color:
[cell setTintColor:[UIColor whiteColor]];
回答2:
Swift:
cell.tintColor = UIColor.whiteColor()
Swift 3.0
cell.tintColor = UIColor.white
回答3:
The best way to do that, i think, is to set accessory to image the following way:
let image = UIImage(named: "some image.png")
cell.accessoryView = image
回答4:
Swift 3.1:
cell.backgroundColor = UIColor.yellow // the accessoryType background
cell.tintColor = UIColor.black // the accessoryType tint color.
回答5:
You can also change the cell's tint color from the storyboard (assuming you are using a xib file)
回答6:
Im my case i need to change contentView color of my CustomCell.
Its can be easy making when u override methods :
override func setHighlighted(highlighted: Bool, animated: Bool) {}
and:
override func setSelected(selected: Bool, animated: Bool) {}
But when i add to my customCell :
cell?.accessoryType = .DisclosureIndicator
i had a problem when view under DisclosureIndicator is not change color. Its looks like:
So i look on subviews of CustomCell and find that DisclosureIndicator is a button. If change background color of this button u have this
So i try to change background color of superview of this button. And its work great.
Full code of myCustomCell setHighlighted func :
override func setHighlighted(highlighted: Bool, animated: Bool) {
if(highlighted){
viewContent.view.backgroundColor = Constants.Colors.selectedBackground
for item in self.subviews {
if ((item as? UIButton) != nil) {
item.superview?.backgroundColor = Constants.Colors.selectedBackground
}
}
} else {
viewContent.view.backgroundColor = Constants.Colors.normalCellBackground
for item in self.subviews {
if ((item as? UIButton) != nil) {
item.superview?.backgroundColor = Constants.Colors.normalCellBackground
}
}
}
}
回答7:
Doesn't work for .disclosureIndicator ?
If someone is here looking for "How to change color for .disclosureIndicator indicator type".
The answer is you can't. BUT:
There is a way. Apply a custom image:
let chevronImageView = UIImageView(image: disclosureIndicatorImage"))
accessoryView = chevronImageView
Additional supporting links:
The image can be downloaded from here. How to change color of the image is here.
来源:https://stackoverflow.com/questions/29451482/change-color-of-accessorytype-swift