Reputation: 24341
I want to set the background image of a custom UINavigationBar
. I googled and found many solutions related to the issue. But still, I am not able to solve the problem.
Here is the image I want to set as background of custom UINavigationBar
:
The code that I am using to set the background image:
import UIKit
class CustomNavigationBarViewController: UIViewController
{
@IBOutlet weak var customNavigationBar: UINavigationBar!
override func viewDidLoad()
{
super.viewDidLoad()
self.customNavigationBar.setBackgroundImage(#imageLiteral(resourceName: "TopGradient"), for: .default)
}
override var prefersStatusBarHidden: Bool
{
return true
}
}
The screenshot of the result that I am getting:
Instead of the image, I am only getting a gray colored background of UINavigationBar
.
Upvotes: 1
Views: 166
Reputation: 2352
You should resize your image. UINavigationBar
has default height of 64 px. Your image height is more than that.
Check this with correct image size. I have resized the image you were using.
Hope this will help.
Upvotes: 1