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

1 回答 1

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;
于 2013-02-27T08:09:40.513 回答