本文介绍了如何将阴影添加到导航栏,而不是默认边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用阴影替换UINavigationBar
中的默认边框.有什么办法可以做到这一点?我尝试使用与向UIView添加阴影相同的方法,但是它增加了NavigationBar的高度.
I want to replace a default border in UINavigationBar
with shadow. Is there any way to achieve this? I have tried using the same approach as with adding shadow to UIView but it increases a height of my NavigationBar.
推荐答案
尝试一下
self.navigationController.navigationBar.layer.shadowColor = UIColor.blackColor().CGColor
self.navigationController.navigationBar.layer.shadowOffset = CGSizeMake(2.0, 2.0)
self.navigationController.navigationBar.layer.shadowRadius = 4.0
self.navigationController.navigationBar.layer.shadowOpacity = 1.0
快捷键3
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.layer.shadowColor = UIColor.black.cgColor
self.navigationController?.navigationBar.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
self.navigationController?.navigationBar.layer.shadowRadius = 4.0
self.navigationController?.navigationBar.layer.shadowOpacity = 1.0
self.navigationController?.navigationBar.layer.masksToBounds = false
}
输出为
这篇关于如何将阴影添加到导航栏,而不是默认边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!