★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(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 }