2010-07-26 45 views

回答

1

UINavigationBar的用於向後導航或應用轉發。您不能將其用於任何其他功能。如果你想在頂部顯示四個按鈕,使用UIToolBar。工具欄可以具有不同功能的多個按鈕。

`使用工具欄創建新

toolbar = [UIToolbar new]; 
    toolbar.barStyle = UIBarStyleDefault; 
    [toolbar sizeToFit]; 
    toolbar.frame = CGRectMake(0, 410, 320, 50); 

    //Add buttons 
    UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                       target:self 
                       action:@selector(pressButton1:)]; 

    UIBarButtonItem *systemItem2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction 
                       target:self 
                       action:@selector(pressButton2:)]; 

    UIBarButtonItem *systemItem3 = [[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemCamera 
    target:self action:@selector(pressButton3:)]; 

    //Use this to put space in between your toolbox buttons 
    UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
    target:nil 
    action:nil]; 

    //Add buttons to the array 
    NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem, systemItem2, flexItem, systemItem3, nil]; 

    //release buttons 
    [systemItem1 release]; 
    [systemItem2 release]; 
    [systemItem3 release]; 
    [flexItem release]; 

    //add array of buttons to toolbar 
    [toolbar setItems:items animated:NO]; 

    [self.view addSubview:toolbar];` 
相關問題