Swift 设置导航栏透明
controller?.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
controller?.navigationController?.navigationBar.shadowImage = UIImage()
如果不起作用,可能是之前的controller影响了,可以放在
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
//设置导航栏背景透明
self.navigationController?.navigationBar.setBackgroundImage(UIImage(),
for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
}
//视图将要消失
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
//重置导航栏背景
self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
self.navigationController?.navigationBar.shadowImage = nil
}
网友评论