UIBarButtonItem backButtonBackgroundImage:被拉伸

时间:2015-03-13 00:01:07

标签: ios objective-c uistoryboard uibarbuttonitem uiappearance

我正在使用UIAppearance设置自定义backButtonBackgroundImage以及隐藏后退按钮标题:

// Back Button Image
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"ZSSBackArrow"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -100) forBarMetrics:UIBarMetricsDefault];

这很有效,但问题是我的箭头图像水平拉伸:

enter image description here

它应该是这样的:

enter image description here

更新:使用上限内嵌会使图片看起来像这样:

enter image description here

有没有办法防止图像被拉伸?

2 个答案:

答案 0 :(得分:3)

更改图像的上限内嵌,使图像符合您的需要:

UIImage *barButtonImage = [[UIImage imageNamed:@"ZSSBackArrow"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,width,0,0)];

这会将图像的宽度保持为指定的宽度。

您可能需要稍微使用数字才能使其正确。

答案 1 :(得分:0)

使用背景图像属性会强制拉伸。尝试使用图像属性并使用图像插入/偏移来定位图像。

相关问题