UITableViewCell accessory not being tinted

前端 未结 2 760
礼貌的吻别
礼貌的吻别 2021-01-04 10:52

I\'ve read multiple Q&A on the topic but none seem to work so here\'s my problem.

I created a custom UITableViewCell and in the Storyboard, I asked for there to

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-04 11:38

    Extension

    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)
            }
        }
    }
    

    Do it

    override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        cell.prepareDisclosureIndicator()
    }
    

    swift 3 :

    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        cell.prepareDisclosureIndicator()
        
    }
    

    Objective-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];
        }
    }
    

提交回复
热议问题