I am trying to give shadow to a UIStackView. My stackview is in a prototypecell having some labels and buttons. Firstly, I have made a reference of stackview with name UIViewBank in a class that is binded to my custom cell:
class CustChatBankCell: UITableViewCell {
@IBOutlet weak var UIViewBank: UIStackView!
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
}
}
And in my Controller I am using the extension in:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:CustChatBankCell = self.tbChat.dequeueReusableCell(withIdentifier: "CustomBankCell") as! CustChatBankCell
cell.UIViewBank.dropShadow()
return cell
}
}
Extension code:
extension UIStackView {
func dropShadow(scale: Bool = true) {
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOpacity = 0.5
self.layer.shadowOffset = CGSize(width: -1, height: 501)
self.layer.shadowRadius = 1
self.layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath
self.layer.shouldRasterize = true
self.layer.rasterizationScale = scale ? UIScreen.main.scale : 1
}
}
But shadow is not appearing.