Change disclosure indicator color on cell selection

前端 未结 7 1809
甜味超标
甜味超标 2021-01-12 01:44

I\'ve read some posts on this, but still can\'t get the answer to my question.

I have a disclosure indicator. \"

相关标签:
7条回答
  • 2021-01-12 02:07

    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
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-12 02:17

    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.

    0 讨论(0)
  • 2021-01-12 02:17

    [[UITableViewCell appearance] setTintColor:[UIColor redColor]];

    0 讨论(0)
  • 2021-01-12 02:18

    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
    
    0 讨论(0)
  • 2021-01-12 02:23

    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;
                        }
                    }
                }
            }
        }
    
    0 讨论(0)
  • 2021-01-12 02:24

    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.

    0 讨论(0)
提交回复
热议问题