我在ios5.1和ios6.0上有两个不同的行为
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:offBackButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
在iOS 6.0上
在iOS 5.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非常聪明,可以根据它来确定图像大小并进行拉伸。