★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-hfxskpwu-ko.html
➤若是连接不是山青咏芝的博客园地址,则多是爬取做者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持做者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
1 //设置导航栏背景为空图片 2 self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
(2)若是要去除这个黑边,一样将导航栏的 shadowImage 设置为一个空的 image 便可。git
1 //设置导航栏阴影为空图片 2 self.navigationController?.navigationBar.shadowImage = UIImage()
(1)在 viewWillAppear 方法中将导航栏背景设置为透明,同时在 viewWillDisappear 方法中又将其还原,这样保证导航栏透明这对当前页面有效,其余页面的导航栏不会变为透明。github
1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 8 //修改导航栏标题文字颜色 9 self.navigationController?.navigationBar.titleTextAttributes = 10 [.foregroundColor: UIColor.white] 11 //修改导航栏按钮颜色 12 self.navigationController?.navigationBar.tintColor = UIColor.white 13 14 //设置视图的背景图片(自动拉伸) 15 self.view.layer.contents = UIImage(named:"bg1.jpg")!.cgImage 16 } 17 18 //视图将要显示 19 override func viewWillAppear(_ animated: Bool) { 20 super.viewWillAppear(animated) 21 22 //设置导航栏背景透明 23 self.navigationController?.navigationBar.setBackgroundImage(UIImage(), 24 for: .default) 25 self.navigationController?.navigationBar.shadowImage = UIImage() 26 } 27 28 //视图将要消失 29 override func viewWillDisappear(_ animated: Bool) { 30 super.viewWillDisappear(animated) 31 32 //重置导航栏背景 33 self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default) 34 self.navigationController?.navigationBar.shadowImage = nil 35 } 36 }