3

在此处输入图像描述

我有一个自定义后退按钮,该按钮未按预期显示,它正在被拉伸,即使后退按钮文本为空,它仍显示“后退”文本。

提前致谢。

4

2 回答 2

4

我通常使用这种技术来使其工作:

  1. 要摆脱默认标题:

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0) forBarMetrics:UIBarMetricsDefault];
    
  2. 使用可调整大小的图像:

    UIImage *backButton = [UIImage imageNamed:@"back.png"];         
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:[backButton resizableImageWithCapInsets:UIEdgeInsetsMake(0, backButton.size.width, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    
于 2013-03-26T18:32:16.693 回答
2

尝试类似的东西

UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];  
UIImage *image = ... your image
[back setBackgroundImage:image forState:UIControlStateNormal];  
[back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
back.frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIBarButtonItem *backbi = [[UIBarButtonItem alloc] initWithCustomView:back];  
self.navigationItem.leftBarButtonItem = backbi;

或发布您的代码。

于 2013-03-26T18:11:11.253 回答