【发布时间】:2019-01-09 18:21:17
【问题描述】:
我试图在我的 ViewController 中的 UIView 的所有四个侧面上建立一个阴影——在我通过 Xcode 向 UIView 添加约束之前,它工作得非常好。如何使 UIView 的阴影在所有四个面上显示并为所有面设置约束?
基本上,我发现每当我通过 Xcode 将约束应用到我设置了阴影的 UIView 时,阴影不会出现在 UIView 的所有四个侧面下。相反,它向左浮动,使右侧和底部完全没有阴影。这可以在下面的屏幕截图中看到。
class RegistrationViewController: UIViewController {
@IBOutlet weak var signUpView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
signUpView.clipsToBounds = true
signUpView.layer.cornerRadius = 20;
signUpView.layer.shadowPath = UIBezierPath(roundedRect: signUpView.bounds, cornerRadius: signUpView.layer.cornerRadius).cgPath
signUpView.layer.shouldRasterize = true
signUpView.layer.shadowColor = UIColor.black.cgColor
signUpView.layer.shadowOffset = .zero
signUpView.layer.shadowOpacity = 1
signUpView.layer.shadowRadius = 20
signUpView.layer.masksToBounds = false
// Do any additional setup after loading the view.
}
}
为什么会发生这种情况?如何在保持预期结果的同时添加约束?
【问题讨论】: