如何在我UIView
的顶部添加阴影我尝试过以下但没有运气......
childView.layer.cornerRadius = 5;
childView.layer.masksToBounds = YES;
childView.layer.shadowOffset = CGSizeMake(-15, 20);
childView.layer.shadowRadius = 5;
childView.layer.shadowOpacity = 0.5;
答案 0 :(得分:13)
Swift 3扩展:
这包括我正在处理的应用的默认值,但您可以更改它们以匹配您在应用中所需的样式。
if __name__ == '__main__':
app = QApplication(sys.argv)
web = QWebEngineView()
web.settings().setAttribute(QWebEngineSettings.FullScreenSupportEnabled, True)
web.page().fullScreenRequested.connect(lambda request: request.accept())
baseUrl = "local"
htmlString = """
<iframe width="560" height="315" src="https://www.youtube.com/embed/L0MK7qz13bU?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
"""
web.setHtml(htmlString, QUrl(baseUrl))
web.show()
sys.exit(app.exec_())
答案 1 :(得分:5)
您需要将子视图的masksToBounds
属性设置为NO
才能使阴影可见。
childView.layer.masksToBounds = NO;
答案 2 :(得分:1)
设置masksToBounds = NO
。你没有看到阴影的原因是因为当masksToBounds为YES时,它完全隐藏在你的视图后面。
如果您的按钮已四舍五入,则可以调整视图的imageEdgeInset值。即:UIEdgeInsetsMake(5, 0, 0, 10);
答案 3 :(得分:1)
1。步骤:首先创建uiview出口
2.Step:
buttonBackgroundView.layer.shadowOpacity = 0.7
buttonBackgroundView.layer.shadowOffset = CGSize(width: 3, height: 3)
buttonBackgroundView.layer.shadowRadius = 15.0
buttonBackgroundView.layer.shadowColor = UIColor.black.cgColor
答案 4 :(得分:0)
尝试将masksToBounds设置为NO。根据此链接Whats the best way to add a drop shadow to my UIView,YES会剪切超出视图边界的图层。
答案 5 :(得分:0)
答案在UIBezierPath
您可以在那里找到一篇非常有趣的文章: https://www.hackingwithswift.com/articles/155/advanced-uiview-shadow-effects-using-shadowpath
layer.shadowOffset = CGSize(width: 0, height: -2)
layer.shadowRadius = 5
layer.shadowPath = UIBezierPath(rect: CGRect(x: -1,
y: -1,
width: self.bounds.width,
height: self.layer.shadowRadius)).cgPath