iphone - navigationBar 中的左栏按钮项

标签 iphone objective-c ios ipad

在 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/

相关文章:

iphone - 如何检查 NSNumber 中的空值

objective-c - XCode 6.4 抛出未将 Objective-C 函数转换为 Swift 的错误

iphone - 按下 UIWebView 中的 textField 时显示 ViewController

ios - XCode 4.0.2 中的 iPhone4 模拟器

objective-c - 在与他人共享代码之前编译一个 Objective C iOS 类

iphone - 保存和恢复 UIWebView 浏览 session

iphone - 如何使用uiimageview修改图像中的像素并在iPhone中显示新图像?

objective-c - 几秒钟后隐藏 OS X 上的鼠标光标

iOS NSDate 和 NSDateFormatter 行为

iPhone -Pthread 条件信号未解除阻塞等待线程