2017-02-27 140 views

回答

3

下面介紹如何使用UIAppearance和UIImage的API來解決這個問題:

// disable image stretching by defining left and top caps. 
let navbarImage = image.stretchableImage(withLeftCapWidth: 1, topCapHeight: 1) 
UINavigationBar.appearance().setBackgroundImage(navbarImage, for: .default) 

實例之前: enter image description here

和修復後: enter image description here

0

嘗試下面method哪些爲我工作。

 var headerview = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 44))    
     let imgview = UIImageView(frame: CGRect(x: 75, y: 0, width: 150, height: 44)) 
     imgview.image = UIImage(named: "ImageName") 
     imgview.contentMode = UIViewContentMode.scaleAspectFit 
     headerview.addSubview(imgview) 
     self.navigationController?.navigationBar.topItem?.titleView = headerview