您可以通过添加 UIView 来做到这一点,然后在其中添加 x=spaceWidth y = 0 的按钮。
查看下面的代码以获取正确的项目(这是在 UINavigationItem 类别中)
1 -
UIView *_rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
[_rightView setBackgroundColor:[UIColor purpleColor]];//debug color
2-
UIButton *aLeftButton = [[UIButton alloc] init];
//...//
aLeftButton.frame = CGRectMake(-15, 0, 44, 44);//in your case +15
[aLeftButton setBackgroundImage:[UIImage imageNamed:buttonName] forState:UIControlStateNormal];
[aLeftButton setBackgroundImage:[UIImage imageNamed:[buttonName stringByAppendingString:@"Selected"]] forState:UIControlStateSelected];
[aLeftButton setAdjustsImageWhenDisabled:NO];
[aLeftButton setAdjustsImageWhenHighlighted:NO];
[aLeftButton addTarget:theSender action:aSelector forControlEvents:UIControlEventTouchUpInside];
[_rightView addSubview:aLeftButton];
UIBarButtonItem *aBarButton = [[UIBarButtonItem alloc] initWithCustomView:_rightView];
[leftBarButtonsItem addObject:aBarButton];`
3
self.leftBarButtonItem = leftBarButtonsItem;