0

I've seen a lot of people doing this:

[[UIToolbar appearance] setBackgroundImage:toolBarImage forBarMetrics:UIBarMetricsDefault];

For me it doesn't work, because my App crashes and says:

-[_UIAppearance setBackgroundImage:]: unrecognized selector sent to instance 0xab8fe80

I already researched and found out that UIAppearance is only available since ios 5, but my simulator is 6.1 and my iPhone too. Also I did this with the NavigationBar which works.

Hope you can help me :) Thanks a lot!!

Jbryson
  • 2,875
  • 1
  • 31
  • 53
user1734282
  • 388
  • 2
  • 4
  • 17

3 Answers3

4

This worked for me:

UIImage* toolbarImage = [UIImage imageNamed: @"toolbar_background.png"];
[[UIToolbar appearance] 
    setBackgroundImage: toolbarImage 
    forToolbarPosition: UIToolbarPositionAny
    barMetrics: UIBarMetricsDefault];
Saxon Druce
  • 17,406
  • 5
  • 50
  • 71
  • It's not necessary to use the appearance proxy, you can set background image to the specific toolar: `[yourToolbar setBackgroundImage: toolbarImage forToolbarPosition: UIToolbarPositionAny barMetrics: UIBarMetricsDefault]` – vahotm Sep 11 '17 at 16:40
2

Check this:

If The UIToolbar is contained within a ViewController.

You cannot change the UIToolbar within AppDelegate if the UIToolbar is contained in a ViewController.

Also see here: IOS 5 unrecognized selector send at appearance proxy for setBackgroundImage

Read all the comments iOS5 changing Background of UIToolbar

Community
  • 1
  • 1
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
0

You should call this method in your app delegate implementation file in the didfinishlaunchingwithoptions: method