gpt4 book ai didi

ios - 如何使用 Bezier Path 添加阴影

转载 作者:行者123 更新时间:2023-11-28 14:53:39 28 4
gpt4 key购买 nike

我已经在 View 的 3 个边上添加了阴影,但没有给出底部阴影,但是在初始加载时,它会在所有角落显示阴影,但是当我滚动时它会显示正确的结果。这是我的代码。

类 ScheduleClassesTableViewCell: UITableViewCell {

let path = UIBezierPath()

//MARK:-
//MARK:- IBOUTLETS

@IBOutlet weak var cellImage: UIImageView!
@IBOutlet weak var openTime: UILabel!
@IBOutlet weak var closeTime: UILabel!
@IBOutlet weak var clockImage: UIImageView!
@IBOutlet weak var instructerNameLabel: UILabel!
@IBOutlet weak var classTypeLabel: UILabel!
@IBOutlet weak var healthClubLocationLabel: UILabel!
@IBOutlet weak var ratingsBtn: UIButton!
@IBOutlet weak var locationBtn: UIButton!
@IBOutlet weak var healthClubName: UILabel!
@IBOutlet weak var healthClubLoc: UILabel!
@IBOutlet weak var shadowView: UIView!

//MARK:-
//MARK:- TableView Life Cycle

override func awakeFromNib() {
super.awakeFromNib()

self.healthClubLoc.isHidden = false
self.ratingsBtn.doCorner(cornerRadius: 2.5)
self.locationBtn.doCorner(cornerRadius: 2.5)
self.ratingsBtn.setBorder(with: UIColor.gray, of: 0.5)
self.locationBtn.setBorder(with: UIColor.white, of: 1.0)
self.cellImage.doCorner(cornerRadius: 2.5)
}

override func draw(_ rect: CGRect) {
super.draw(rect)
self.shadowView.layoutIfNeeded()
path.move(to: CGPoint(x: 0.0, y: shadowView.frame.size.height))
path.addLine(to: CGPoint(x: 0.0, y: 0.0))
path.addLine(to: CGPoint(x: shadowView.frame.size.width, y: 0.0))
path.addLine(to: CGPoint(x: shadowView.frame.size.width, y: shadowView.frame.size.height))
self.shadowView.drawShadow(shadowColor: UIColor.red, shadowOpacity: 0.8, shadowPath: path, shadowRadius: 2, cornerRadius: 0.0)

}

before scrolling

before scrolling

after scrolling

after scrolling

最佳答案

override func draw(_ rect: CGRect) {
super.draw(rect)

path.move(to: CGPoint(x: 0.0, y: shadowView.frame.size.height))
path.addLine(to: CGPoint(x: 0.0, y: 0.0))
path.addLine(to: CGPoint(x: shadowView.frame.size.width, y: 0.0))
path.addLine(to: CGPoint(x: shadowView.frame.size.width, y: shadowView.frame.size.height))
self.shadowView.drawShadow(shadowColor: UIColor.red, shadowOpacity: 0.8, shadowPath: path, shadowRadius: 2, cornerRadius: 0.0)
layoutIfNeeded()

}

请更新您的代码

关于ios - 如何使用 Bezier Path 添加阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49586300/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com