在 Iphone SDK 的导航栏上添加多个按钮

Addimg mutiple button on Navigation bar in Iphone SDK(在 Iphone SDK 的导航栏上添加多个按钮)

本文介绍了在 Iphone SDK 的导航栏上添加多个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将两个带有自定义图像的按钮添加到具有特定位置的导航栏.

I want to add two buttons with custom image to Navigation Bar with some specific position.

我找到了解决方案,但它适用于右/左导航栏按钮.

I found solution But it is for Right/Left Navigation Bar Button.

我的代码是:

 NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2];
 UIToolbar *tools = [[UIToolbar alloc]
                    initWithFrame:CGRectMake(0.0f, 0.0f, 90.0f, 55.01f)];
// Add Pin button.

UIBarButtonItem *bi1 = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(Edit:)];
bi1.style = UIBarButtonItemStyleBordered;
bi1.width = 45;
[buttons addObject:bi1];
[bi1 release];

// Add Hot Spot button.
UIBarButtonItem *bi2 = [[UIBarButtonItem alloc] initWithTitle:@"+" style:UIBarButtonItemStylePlain target:self action:@selector(Add:)];
bi2.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi2];
[bi2 release];

// Add buttons to toolbar and toolbar to nav bar.
[tools setItems:buttons animated:NO];
[buttons release];

 // Add toolbar to nav bar.
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
self.navigationItem.rightBarButtonItem = twoButtons;
[twoButtons release];

我该怎么做?

推荐答案

UIView *vieww =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[vieww addSubview:yourBtn1];
[vieww addSubview:yourBtn2];

[self.navigationController.navigationBar addSubview:vieww];    

如果你想删除 yourButtonView 那么 make 是全局对象;

And if you want to remove yourButtonView then make is global object;

in .h

UIView *vieww;

并在 .m

-(void)viewWillDisappear:(BOOL)animated
{
    [vieww removeFromSuperview];
}

或关注更多链接

这篇关于在 Iphone SDK 的导航栏上添加多个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 Iphone SDK 的导航栏上添加多个按钮