我有一个自定义后退按钮,该按钮未按预期显示,它正在被拉伸,即使后退按钮文本为空,它仍显示“后退”文本。
提前致谢。
我通常使用这种技术来使其工作:
要摆脱默认标题:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0) forBarMetrics:UIBarMetricsDefault];
使用可调整大小的图像:
UIImage *backButton = [UIImage imageNamed:@"back.png"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[backButton resizableImageWithCapInsets:UIEdgeInsetsMake(0, backButton.size.width, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
尝试类似的东西
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;
或发布您的代码。