Reputation: 33654
In iOS5 we have leftBarButtonItems that we can set to a navigation bar, how can I do this for pre-iOS 5? I basically have an array of UIBarButtonItem that I wanted to set the bar to.
Upvotes: 2
Views: 7905
Reputation: 4920
You can build own bar, and add it as left button:
UIBarButtonItem *firstButton = [[UIBarButtonItem alloc] initWithTitle:@"First" style:UIBarButtonItemStyleBordered target:self action:@selector(firstButtonAction:)];
UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithTitle:@"Second" style:UIBarButtonItemStyleBordered target:self action:@selector(secondButtonAction:)];
UIToolbarTransparent *toolbar = [UIToolbarTransparent new];
[toolbar setFrame:CGRectMake(0,0, 140,44)];
[toolbar setItems:[NSArray arrayWithObjects:firstButton, secondButton, nil]];
UIBarButtonItem *customBarButton = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
self.navigationItem.leftBarButtonItem = customBarButton;
UIToolbarTransparent
.h
#import <Foundation/Foundation.h>
@interface UIToolbarTransparent : UIToolbar {
}
.m
#import "UIToolbarTransparent.h"
@implementation UIToolbarTransparent
- (id)init {
if (self = [super init]) {
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.translucent=YES;
}
return self;
}
@end
Upvotes: 10
Reputation: 6176
samfisher is right, but you can just use a custom UIView that contains your UIButtons, than use that UIView as a (single) leftBasButtonItem
Upvotes: 2