oc :
//按比例顯示圖片
UIImage *backGroundImage = [UIImage imageNamed:@”NavigationBar”];
backGroundImage = [backGroundImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];
[self.navigationController.navigationBar setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];
swift:
var image = UIImage()
image = UIImage.init(named: "NavigationBar")!
//這句話按照比例延伸,顯示完整圖片
image = image.resizableImage(withCapInsets: UIEdgeInsets.zero, resizingMode: UIImage.ResizingMode.stretch)
navigationBar.setBackgroundImage(image, for: .default)