扭曲的导航栏自定义后退按钮

时间:2013-03-26 18:03:57

标签: iphone ios

enter image description here

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

提前致谢。

2 个答案:

答案 0 :(得分: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];
    

答案 1 :(得分: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;

或发布您的代码。