I\'ve read some posts on this, but still can\'t get the answer to my question.
I have a disclosure indicator.
Swift 3 - a simple Table View class that can show a disclosure indicator or not using the showsDisclosure
boolean when configuring the cell. right now the disclosure arrow tint color is hard coded, but your color choice could easily be passed in through the configure function as well if you wanted a more reusable cell.
Note that the 'chevron' image is set to be a template image in the asset catalog, which means that it can be tinted a color. You can alternatively make a UIImage into a template image in code like so: UIImage(named: "chevron")?.withRenderingMode(.alwaysTemplate)
class HeaderTableViewCell: UITableViewCell {
@IBOutlet weak var sectionTitle: UILabel!
override func awakeFromNib() {
sectionTitle.textColor = .black
}
func configure(title: String, showsDisclosure: Bool = false) {
self.sectionTitle.text = title
if showDisclosure {
//add custom disclosure arrow
let chevronImgView = UIImageView(image: UIImage(named: "chevron"))
chevronImgView.tintColor = .red
self.accessoryType = .disclosureIndicator
self.accessoryView = chevronImgView
} else {
self.accessoryType = .none
self.accessoryView = nil
}
}
}
I was facing the same problem and found even you're struggling with this...though its quite late answer but i sorted out my issue by writing the following line,
cell.selectionStyle = UITableViewCellSelectionStyleNone;
it stopped accessory type UITableViewCellAccessoryDisclosureIndicator from being white when selected.
Hope this helped.
[[UITableViewCell appearance] setTintColor:[UIColor redColor]];
Swift 3
Add a custom accessory view:
Example 1:
cell.accessoryView = UIImageView(image: UIImage(named: "accessory.png"))
Example 2:
Nested in an view container for a small source image:
let accessoryView = UIView(frame: CGRect(x: 0, y: 0, width: 24, height: 50))
let accessoryViewImage = UIImageView(image: UIImage(named: "accessory.png"))
accessoryViewImage.center = CGPoint(x: 12, y: 25)
accessoryView.addSubview(accessoryViewImage)
cell.accessoryView = accessoryView
Try something like this. Probably you'll be able to achieve what you want.
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
for (id obj in cell.subviews){
if([obj isKindOfClass:[UIButton class]]) {
UIButton *button = obj;
for(id btnObj in button.subviews){
if([btnObj isKindOfClass:[UIImageView class]]) {
UIImageView *imgView = btnObj;
UIImage *image = [imgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
imgView.image = image;
imgView.tintColor = cell.backgroundColor;
}
}
}
}
}
You need to use a custom accessory view for this. Syntax:
cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"accessory.png"]] autorelease];
Here you are assigning an image view with an image accessory.png
to your cell's accessory view.