0

I'm unable to override the draw method of the UIToolbar class. I want to customize the toolbar with a background image and some buttons.

I tried this both in the AppDelegate.m and then also in my viewcontroller implementation file. here's my code:

@implementation UIToolbar (CustomImage)

- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"tabbar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}

@end

I'm adding the toolbar with this code in the view controller viewDidLoad method:

 UIBarButtonItem *flexiableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:nil];

    NSArray *items = [NSArray arrayWithObjects:item1, flexiableItem, item2, nil];
    self.toolbarItems = items;

thanks for any help

hanumanDev
  • 6,592
  • 11
  • 82
  • 146

1 Answers1

1

Maybe better add this code at application launch?

[[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbar.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Shimanski Artem
  • 1,240
  • 1
  • 11
  • 7