1
This my simulator screen shot 進口的UIKit沒有工作導航標題背景圖像
class NewsTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
addCustomNavigationBarToView()
}
//這是我的自定義導航欄功能
func addCustomNavigationBarToView(){
//這裏我創建的導航欄變量
let navigationBar = UINavigationBar(frame: CGRect(x:0, y:0, width: self.view.frame.size.width, height: 100))
let navBackgroundImage:UIImage! = UIImage(named: "BarBa.jpg") self.navigationController?.navigationBar.setBackgroundImage(navBackgroundImage,for: .default)
//我創建了導航項目變量並設置圖像
let navigationItem = UINavigationItem()
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 220, height: 90))
imageView.contentMode = .scaleAspectFit
let image = UIImage(named: "logo.png")
imageView.image = image
navigationItem.titleView = imageView
// Create left and right button for navigation item
let leftButton = UIBarButtonItem(title: "Save", style: UIBarButtonItemStyle.plain, target: self, action: Selector(("saveButtonClicked:")))
navigationItem.leftBarButtonItem = leftButton
//tapping the menu button work
// Assign the navigation item to the navigation bar
navigationBar.items = [navigationItem]
self.view.addSubview(navigationBar)
}
}