将导航栏添加到所需位置

时间:2013-02-27 07:43:55

标签: xcode ipad uibutton uinavigationbar

我有应用程序我希望导航栏上的按钮应该在所需的位置,但它没有完成我找到了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];

1 个答案:

答案 0 :(得分: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;