按右栏按钮项目移动左栏按钮项目

时间:2014-01-23 15:02:57

标签: ios objective-c uibarbuttonitem

我的网页浏览导航栏上有三个左栏按钮项目。一个回到我的应用程序菜单和后退和前进按钮。我有一个右键栏打开一个活动视图控制器。当我按下右键时,左侧的前进和后退按钮会向下移动并离开导航栏。

- (void)viewDidLoad
{   
    leftBarButtonItems = [NSArray arrayWithObjects:@"Menu", @"Back", @"Forward", nil];

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSString *urlAddress = @"http://www.littleheartrecords.com/releases.html";
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];

    UIBarButtonItem *systemAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showMenu)];
    self.navigationItem.rightBarButtonItem = systemAction;

    UIBarButtonItem *openItem = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStylePlain target:self action:@selector(openButtonPressed)];
    self.navigationItem.leftBarButtonItem = openItem;

    UIImage *back = [UIImage imageNamed:@"back_arrow"];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle:@"" style: UIBarButtonItemStylePlain target:self action:@selector(GoBack)];
    [backButton setImage:back];

    UIImage *forward = [UIImage imageNamed:@"forward_arrow"];
    UIBarButtonItem *forwardButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(GoForward)];
    [forwardButton setImage:forward];

    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:openItem, backButton, forwardButton, nil];
}

enter image description here enter image description here enter image description here

1 个答案:

答案 0 :(得分:3)

奇怪的是,对我来说有用的是将图像按钮的标题设置为单个空格:

barButtonItem.title = @" ";
barButtonItem.image = [UIImage imageNamed:@"MenuIcon.png"];