我将图像添加到导航控制器后退按钮,如下所示:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ITButton.png"] style:UIBarButtonItemStyleBordered target:nil action:nil];
它工作正常,因此,我的图像与<回符号。图像略高于符号,我希望两者都居中。我不知道为什么。我尝试使用以下方法进行调整:
[self.navigationItem.backBarButtonItem setImageInsets:UIEdgeInsetsMake(10, 0, 0, 0)];
但没有改变。
答案 0 :(得分:0)
有很多方法可以解决这个问题,我遇到了同样的问题然后我已经解决了这个问题
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if([self.navigationController.viewControllers objectAtIndex:0] != self)
{
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 26, 26)];
[backButton setImage:[UIImage imageNamed:@"home.png"] forState:UIControlStateNormal];
[backButton setShowsTouchWhenHighlighted:TRUE];
[backButton addTarget:self action:@selector(popViewControllerWithAnimation) forControlEvents:UIControlEventTouchDown];
UIBarButtonItem *barBackItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.hidesBackButton = TRUE;
self.navigationItem.leftBarButtonItem = barBackItem;
}
}
-(void)popViewControllerWithAnimation
{
[self.navigationController popViewControllerAnimated:YES];
}