在 iOS5 中,我们可以将 leftBarButtonItem 设置为导航栏,对于 iOS 5 之前的版本我该如何做?我基本上有一个 UIBarButtonItem 数组,我想将其设置为。
最佳答案
您可以建立自己的栏,并将其添加为左按钮:
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
关于iphone - navigationBar 中的左栏按钮项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9557341/