0

To set UIToolBar background Image I use the below code.

UIToolbar *tool=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100.0)];
[tool setTintColor:[UIColor darkGrayColor]];
UIBarButtonItem *btn=[[UIBarButtonItem alloc] initWithTitle:@"Load" style:UIBarButtonItemStyleBordered target:nil action:nil];
[tool setItems:[NSArray arrayWithObject:btn]];
 UIImage *barImage=[[UIImage imageNamed:@"BarBg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(27,0,27,0)];
[tool setBackgroundImage:barImage forToolbarPosition:UIToolbarPositionBottom
              barMetrics:UIBarMetricsDefault];
 [self.view addSubview:tool];

This shows the following output

But question arises where is the purple colour background image, which I had set?

enter image description here

If I change the position top the output changes to

   [tool setBackgroundImage:barImage forToolbarPosition:UIToolbarPositionTop
                  barMetrics:UIBarMetricsDefault];

This is what I expect, when setting background image.

enter image description here

So I don't have any clear idea when to use UIToolBarPositionTop or UIToolBarPositionBottom?

weber67
  • 525
  • 1
  • 9
  • 18

1 Answers1

0

In the Apple docs is stated:

UIToolbarPositionBottom: Indicates the toolbar is at the top of its containing view.

UIToolbarPositionTop: Indicates the toolbar is at the bottom of its containing view.

Definitelly this is a bit strange (UIToolbarPositionTop means at bottom...), but, thats the way it is...

Maybe it's easier to think of it as: That content is above (Top) of the toolbar in UIToolbarPositionTop

LaborEtArs
  • 1,938
  • 23
  • 27