导航栏中的左栏按钮项目

时间:2012-03-04 17:50:34

标签: iphone objective-c ios ipad

在iOS5中,我们将leftBarButtonItems设置为导航栏,如何在iOS 5之前执行此操作?我基本上有一个UIBarButtonItem数组,我想把它设置为。

2 个答案:

答案 0 :(得分:10)

您可以构建自己的栏,并将其添加为左键:

    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;

UIToolbar透明

·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

答案 1 :(得分:2)

samfisher是对的,但您可以使用包含UIButtons的自定义UIView,而不是将UIView用作(单个)leftBasButtonItem