2013-02-27 57 views
0

我有應用程序我希望導航欄上的按鈕應該在所需的位置,但它沒有完成我已經找到了rightBarButton和leftBarButton的方法,但我想要在導航欄的中心添加到導航欄到所需的位置

UIButton *settingsView = [[UIButton alloc] initWithFrame:CGRectMake(0,0,40,40)]; 
[settingsView addTarget:self action:@selector(SettingsClicked) forControlEvents:UIControlEventTouchUpInside]; 
[settingsView setBackgroundImage:[UIImage imageNamed:@"login btn.png"] forState:UIControlStateNormal]; 
UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithCustomView:settingsView]; 
[self.navigationItem setRightBarButtonItem:settingsButton]; 

回答

0
NSMutableArray *arrayOfItems = [[NSMutableArray alloc] init]; 

UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] 

[arrayOfItems addObject:flexibleSpace]; 
[arrayOfItems addObject:theItemYouWantCentered]; 
[arrayOfItems addObject:flexibleSpace]; 

self.navigationItem.leftBarButtonItems = arrayOfItems;