I want to make my UIToolBar have a transparent background (similar to iBooks) but I'm having no luck with setting the translucent
property.
Here's my code:
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
NSMutableArray *toolBarItems = [[NSMutableArray alloc] init];
[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil]];
[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Source" style:UIBarButtonItemStyleBordered target:nil action:nil]];
[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Aa" style:UIBarButtonItemStyleBordered target:nil action:nil]];
[toolBarItems addObject:[[UIBarButtonItem alloc] initWithTitle:@"Rabbit" style:UIBarButtonItemStyleBordered target:nil action:nil]];
toolBar.items = toolBarItems;
toolBar.translucent = YES;
[self.view addSubview:toolBar];
It still comes out like this:
If you want toolbar as Transparent :
[toolBar setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
and if you want toolbar as Translucent :
[toolBar setBarStyle:UIBarStyleBlack];
toolBar.translucent = YES;
Hope it helps you.
One option is to subclass UIToolbar and override the draw method, the buttons will continue to draw themselves as normal:
@interface TransparentToolbar : UIToolbar
{
}
@implementation TransparentToolbar
// drawRect stub, toolbar items will still draw themselves
- (void)drawRect:(CGRect)rect
{
return;
}
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With