0

ナビゲーションバー(ナビゲーション付き)があり、ナビゲーションバーに2つのボタンが含まれていますが、ボタンの1つを左に割り当てると、ナビゲーションボタンが消えます(doughh)。さらに2つのボタン?ここで私が使用するコード:

viewDidLoadから

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];

だから私の2番目のボタンはに設定されています

setLeftBarButtonItem

setCenterのようなものはありますか?またはx、yで位置を設定する方法?? ナビゲーションのためにボタンを左側に保持する2つのボタンが必要です(3つのボタン)

ありがとう!

4

1 に答える 1

1

このコードを使用して、ナビゲーション バーに 2 つ以上のボタンを追加する方法を理解してください

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];
于 2011-02-25T05:12:48.767 に答える