Changing background color of selected cell?

后端 未结 30 2853
太阳男子
太阳男子 2020-11-29 00:22

Does anyone know how to change the background color of a cell using UITableViewCell, for each selected cell? I created this UITableViewCell inside the code for TableView.

30条回答
  •  独厮守ぢ
    2020-11-29 00:53

    In Swift

    let v = UIView()
        v.backgroundColor = self.darkerColor(color)
        cell?.selectedBackgroundView = v;
    
    ...
    
    func darkerColor( color: UIColor) -> UIColor {
        var h = CGFloat(0)
        var s = CGFloat(0)
        var b = CGFloat(0)
        var a = CGFloat(0)
        let hueObtained = color.getHue(&h, saturation: &s, brightness: &b, alpha: &a)
        if hueObtained {
            return UIColor(hue: h, saturation: s, brightness: b * 0.75, alpha: a)
        }
        return color
    }
    

提交回复
热议问题