我有一个自定义后退按钮,按钮没有按预期显示,正在拉伸,即使后退按钮文本为空,它仍然显示“后退” 文本。
提前致谢。
答案 0 :(得分:4)
我通常使用这种技术使其工作:
要摆脱默认标题:
[[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];
答案 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;
或发布您的代码。