Change disclosure indicator color on cell selection

前端 未结 7 1860
甜味超标
甜味超标 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
            }
        }
    }
    

提交回复
热议问题