Changing the UINavigationBar background image

后端 未结 7 478
时光取名叫无心
时光取名叫无心 2020-12-01 08:29

I\'ve been trying to change the background image of the UINavigationBar of my application. I tried several ways. First I added to my AppDelegate class the following code:

7条回答
  •  生来不讨喜
    2020-12-01 08:37

    Starting in iOS 5 you should use the -setBackgroundImage:forBarMetrics: method:

    [myNavbar setBackgroundImage:[UIImage imageNamed: @"UINavigationBarBackground.png"] 
                   forBarMetrics:UIBarMetricsDefault];
    

    And in Swift 4:

    navigationBar.setBackgroundImage(UIImage(named: "UINavigationBarBackground.png"),
                   for: .default)
    

提交回复
热议问题