导航栏中的iphone 2按钮

导航栏中的iphone 2按钮,iphone,button,navbar,Iphone,Button,Navbar,我有一个导航栏(带导航),导航栏上有两个按钮,但如果我将其中一个按钮分配到左侧,我的导航按钮将消失(doughh), 那我怎么能有,我的导航按钮,还有另外两个按钮呢? 下面是我使用的代码: 从视图下载 UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; infoButton.frame = CGRectMake(0, 10, 40, 30); UIImage *img = [UIImage image

我有一个导航栏(带导航),导航栏上有两个按钮,但如果我将其中一个按钮分配到左侧,我的导航按钮将消失(doughh), 那我怎么能有,我的导航按钮,还有另外两个按钮呢? 下面是我使用的代码:

从视图下载

UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
infoButton.frame = CGRectMake(0, 10, 40, 30);
UIImage *img = [UIImage imageNamed:@"eye.png"];
[infoButton setImage:img forState:UIControlStateNormal]; [img release];
//[infoButton setTitle:@"xuxu"forState:UIControlStateNormal];
[infoButton addTarget:self action:@selector(infoButtonAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
[self.navigationItem setRightBarButtonItem:modalButton animated:YES];
[modalButton release];


UIButton* iButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
iButton.frame = CGRectMake(0, 10, 40, 30);
UIImage *imag = [UIImage imageNamed:@"eye.png"];
[iButton setImage:imag forState:UIControlStateNormal]; [imag release];
//[infoButton setTitle:@"xuxu"forState:UIControlStateNormal];
[infoButton addTarget:self action:@selector(infoButtonAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalButton2 = [[UIBarButtonItem alloc] initWithCustomView:iButton];
[self.navigationItem setLeftBarButtonItem:modalButton2 animated:YES];
[modalButton2 release];
所以我的第二个按钮设置为

巴布托宁

有没有像setCenter这样的东西??或者用x,y设置位置的方法?? 我需要2个按钮将我的按钮保持在左侧,以便导航(3个按钮)


谢谢大家!

使用此代码了解如何在导航栏上添加两个或更多按钮

UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    infoButton.frame = CGRectMake(0, 10, 40, 30);
    UIImage *img = [UIImage imageNamed:@"eye.png"];
    [infoButton setImage:img forState:UIControlStateNormal]; [img release];
    [infoButton setTitle:@"xuxu"forState:UIControlStateNormal];
    [infoButton addTarget:self action:@selector(infoButtonAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *modalButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
    [self.navigationItem setRightBarButtonItem:modalButton animated:YES];
    [modalButton release];


    UIButton* iButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    UIButton* aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    aButton.frame = CGRectMake(0, 10, 40, 30);
    iButton.frame = CGRectMake(42, 10, 40, 30);
    UIImage *imag = [UIImage imageNamed:@"eye.png"];
    [iButton setImage:imag forState:UIControlStateNormal]; 
     [aButton setImage:imag forState:UIControlStateNormal]; 
    [imag release];
    [infoButton setTitle:@"xuxu"forState:UIControlStateNormal];


    [iButton addTarget:self action:@selector(infoButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [aButton addTarget:self action:@selector(infoButtonAction) forControlEvents:UIControlEventTouchUpInside];
    UIView *viewForAdd=[[UIView alloc] initWithFrame:CGRectMake(0,0,100,50)];
    [viewForAdd addSubview:iButton];
    [viewForAdd addSubview:aButton];
    UIBarButtonItem *modalButton2 = [[UIBarButtonItem alloc] initWithCustomView:viewForAdd];
    [self.navigationItem setLeftBarButtonItem:modalButton2 animated:YES];
    [modalButton2 release];

你需要三个按钮,左边2个,右边1个。非常感谢你,这正是我需要的,能够设置x位置,干杯