1

I can not change the uitoolbar background image. gives error.

This navigationBar code is working.

UIImage *navBackgroundImage = [UIImage imageNamed:@"bartop.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

But this toolbar code is not working and gives error.

UIImage *navBackgroundImage = [UIImage imageNamed:@"bartop.png"];
[[UIToolbar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

Where is my wrong?


UPDATE:

This code is working:

UIImage *testimage = [[UIImage imageNamed:@"bartop"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsLandscapePhone];
Salieh
  • 693
  • 2
  • 7
  • 12

1 Answers1

6

According to the documentation, the method you need to use with UIToolbar is

- setBackgroundImage:(UIImage *)backgroundImage forToolbarPosition:(UIToolbarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics

You are using

- setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics

Try using that and see if it works for you.

More info here.

lostInTransit
  • 70,519
  • 61
  • 198
  • 274