我需要this,但first cell is having no shadow but the second cell gets such shadow没有获得表格视图单元格的影子。 我已将表格视图单元格的内容视图与单元格的viewcontroller连接起来并执行了此操作:
import UIKit
class staydetailsTableViewCell: UITableViewCell {
@IBOutlet weak var price: UILabel!
@IBOutlet weak var Content: UIView!
@IBOutlet weak var image1: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
Content.layer.masksToBounds = false
Content.layer.cornerRadius = 5
Content.layer.shadowColor = UIColor.red.cgColor
Content.layer.shadowOffset = CGSize(width: 0, height: 20)
Content.layer.shadowRadius = 20
Content.layer.opacity = 1
Content.layer.borderColor = UIColor.lightGray.cgColor
Content.layer.borderWidth = 1//(except for this nothing else is woking)
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
答案 0 :(得分:2)
尝试使用layoutSubviews
这是您可以使用的代码段。绝对不需要添加名为contentView的视图来显示阴影,每个UITableViewCell
都带有embedded contentView
override func layoutSubviews() {
super.layoutSubviews()
self.layer.cornerRadius = 5
self.contentView.layer.cornerRadius = 5
let shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: radius)
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.red.cgColor
self.layer.shadowOffset = CGSize(width: 0.5, height: 1)
self.layer.shadowOpacity = 0.25
self.layer.shadowPath = shadowPath.cgPath
}