iOS - 在stackview中查看不显示阴影

时间:2018-06-14 11:00:16

标签: ios shadow uistackview

我使用UIStackView设计了弹出视图。 我试图隐藏到#34;警报视图"如图所示。阴影的参数显示在右侧。

Storyboard design

但是在我运行代码后它没有显示阴影。

After running on device

但如果我在没有UIStackView的情况下设计这个弹出窗口,它会显示阴影。

这背后的原因是什么?

1 个答案:

答案 0 :(得分:0)

您的AlertView已勾选clipToBounds。这就是为什么你没有看到阴影添加到AlertView的原因。取消选中它以使其正常工作

O / P,clipToBounds勾选

enter image description here

enter image description here

**取消选中ClipToBounds后的O / P **

enter image description here enter image description here

修改

虽然我不确定,但您为Shadow Radius等属性设置的IBInspectable可能设置不正确,请尝试以编程方式设置阴影

    self.alertView.layer.shadowRadius = 3
    self.alertView.layer.shadowOffset = CGSize(width: 2, height: 4)
    self.alertView.layer.shadowOpacity = 2
    self.alertView.layer.shadowColor = UIColor.black.cgColor

如果这样可行,那么您可以使用您的IBInspectables解决问题