I want to set full image on UINavigationBar
, for this I have:
@2x image (640 x 128)
@3x image (960 x 192)
Below Screenshot is the issue:
Please refer this yellow outline. This portion is cutting.
I have written this code to add image:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named:"nav-bar-b"),for: .any, barMetrics: .default)
}
Please help me to provide a better solution.
try this code in viewDidLoad
UINavigationBar.appearance().setBackgroundImage(UIImage(named: "image")!.resizableImage(withCapInsets: UIEdgeInsets.zero, resizingMode: .stretch), for: .default)
I have fixed this issue like this :-
Take navigation image base on device size otherwise destroyed navigation image.
iPhone 6P => //1242 × 191 pixels
iPhone 6 = > //750 × 128 pixels
iPhone 5 = > //640 × 128 pixels
1.self.navigationController.navigationBar.setBackgroundImage(image, forBarMetrics: .Default)
2.The height of navigation bar is changed from 44 points (88 pixels) to 64 points (128 pixels).
Create a resizeable image. So the image will be scaled vertically and horizontally to fit the navigation bar including the status bar.
For Swift 3:
or