Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

left bar button items in navigationBar

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.

like image 643
adit Avatar asked Feb 20 '26 22:02

adit


1 Answers

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
like image 174
Tomasz Wojtkowiak Avatar answered Feb 22 '26 10:02

Tomasz Wojtkowiak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!