I have a table which has custom cells,
like the one in the image, I have the background to be gray, but my goal is for the gray to be in degrades, that is, to have a stronger gray from the right to the lighter one on the left, example image:
So far I have
I leave the code of the cell class:
class PanelHomeTableViewCell: UITableViewCell {
@IBOutlet weak var strLblTitleOptionsMenu: UILabel!
@IBOutlet weak var imgOptionsMenu: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
The Method where I set the background gray
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let mainCell = Bundle.main.loadNibNamed("PanelHomeTableViewCell", owner: self, options: nil)?.first as! PanelHomeTableViewCell
mainCell.selectionStyle = .none
// SETEO GRIS ; QUIERO DEGRADES
mainCell.backgroundColor = Utils.Color.COLOR_E8E8E8
mainCell.strLblTitleOptionsMenu.textColor = Utils.Color.COLOR_2B5034
switch (indexPath.section)
{
case 0:
mainCell.strLblTitleOptionsMenu.text=NSLocalizedString("strLblOption1",comment:"")
mainCell.imgOptionsMenu.image = UIImage.init(named:"PagarMenu")
return mainCell
case 1:
mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption2",comment:"")
mainCell.imgOptionsMenu.image = UIImage.init(named:"BillingMenu")
return mainCell
case 2:
mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption3",comment:"")
mainCell.imgOptionsMenu.image = UIImage.init(named:"CollectionNotificationsMenu")
return mainCell
case 3:
mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption4",comment:"")
mainCell.imgOptionsMenu.image = UIImage.init(named:"billingQueryMenu")
return mainCell
case 4:
mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption5",comment:"")
mainCell.imgOptionsMenu.image = UIImage.init(named:"MovsBalanceMenu")
return mainCell
case 5:
mainCell.strLblTitleOptionsMenu.text = NSLocalizedString("strLblOption6",comment:"")
mainCell.imgOptionsMenu.image = UIImage.init(named:"CashOutMenu")
return mainCell
default:
break
}
return mainCell
}
i use xcode with swift
To apply a background with a gradient color to your cell you can use the following extension:
And to use it, it would be as follows:
or in your case it would be