table 未显示单元格阴影
table view cell shadow not coming
我需要 this but the first cell is having no shadow but the second cell gets such shadow 不获取 table 视图单元格的阴影。
我已将 table 视图单元格的内容视图与单元格的 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
}
}
尝试使用 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
}
我需要 this but the first cell is having no shadow but the second cell gets such shadow 不获取 table 视图单元格的阴影。 我已将 table 视图单元格的内容视图与单元格的 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
}
}
尝试使用 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
}