在Iphone SDK中的导航栏上添加多个按钮 [英] Addimg mutiple button on Navigation bar in Iphone SDK

查看:72
本文介绍了在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中的导航栏上添加多个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆