表视图单元格阴影未来

问题描述 投票:1回答:1

我需要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
    }

}
ios swift uitableview cell shadow
1个回答
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
    }
© www.soinside.com 2019 - 2024. All rights reserved.