I am changing the size of each TableViewCell with:
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60
}
Then, within the custom cell class, I am inserting a 'gradientLayer' as a sublayer to the Cell's layer property:
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
...
gradientLayer.frame = self.layer.bounds
layer.insertSublayer(gradientLayer, at: 0)
...
}
However, the gradient is not filling up the whole cell:

Does anyone know why this is happening/how I can fix it?
Thank you.

If you use a plain
UITableViewCell:You need to make sure that you're adding the gradient to the contentView's layer.
And this would work just fine.
If you use a custom
UITableViewCellclass :Now, if you are using a custom cell class, you will need to override the
layoutSubviews()method like so :This ensures that your gradient frame is always equal to your contentView frame at anytime.
Your custom cell class would then look like this:
Just let me know if you have any additional questions !