在iOS5.1上设置后退按钮背景图像怪异行为

时间:2012-12-04 19:40:29

标签: ios6 uibarbuttonitem back-button ios5.1 uiappearance

我在ios5.1和ios6.0上有两个不同的行为

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:offBackButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

On iOS 6.0 everything is OK 在iOS 6.0上

On iOS5.1 ??? 在iOS 5.1 ???

有什么我做得不好吗?

1 个答案:

答案 0 :(得分:0)

您需要使用UIImage指定可伸缩的UIEdgeInsets,如下所示:

UIImage *normalStateImage = [[UIImage imageNamed:@"image"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
UIImage *pressedStateImage = [[UIImage imageNamed:@"image-pressed"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:normalStateImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:pressedStateImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

iOS 6.x非常聪明,可以根据它来确定图像大小并进行拉伸。