カスタマイズされたナビゲーションバーに2つのボタンを実装しようとしています。1つはカスタマイズされた戻るボタン用で、もう1つは設定UIViewController用です。私が最初に戻るボタンを実装したとき、それはうまく表示され、leftBarButtonItemとして実装したものと同様に機能します。ただし、2番目のUIBarButtonItemを実装しようとすると、戻るボタンと重なっています。
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 41)];
navBar.delegate = self;
UINavigationItem *topItem = [[UINavigationItem alloc] initWithTitle:@"Create QR(URL)"];
[navBar pushNavigationItem:topItem animated:NO];
UIImage *buttonImage = [UIImage imageNamed:@"back.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
topItem.leftBarButtonItem = customBarItem;
UIImage *buttonImageSettings = [UIImage imageNamed:@"setting.png"];
UIButton *buttonSetting = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImageSettings forState:UIControlStateNormal];
buttonSetting.frame = CGRectMake(220, 0, buttonImageSettings.size.width, buttonImageSettings.size.height);
[buttonSetting addTarget:self action:@selector(settings) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarItemSetting = [[UIBarButtonItem alloc] initWithCustomView:buttonSetting];
topItem.rightBarButtonItem = customBarItemSetting;
[self.view addSubview:navBar];