uibarbuttonitem iOs 6 landscape的自定义图像

时间:2012-09-25 13:54:20

标签: iphone background uibarbuttonitem ios6 landscape

我使用此代码自定义iOS 5的barbutton并且它正常工作:

UIImage *barButton = [[UIImage imageNamed:@"bar-button"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:barButton forState:UIControlStateNormal
                                      barMetrics:UIBarMetricsDefault];

当我在iOS 5上将设备旋转到横向时,结果如下:

enter image description here

现在有了iOs 6,结果是:

enter image description here

当设备处于横向状态时,发生了什么以及如何正确调整图像大小?

1 个答案:

答案 0 :(得分:3)

你应该提供一个风景图像并使用它:

UIImage *barButton = [[UIImage imageNamed:@"bar-button"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
UIImage *barButton_land = [[UIImage imageNamed:@"bar-button_land"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:barButton forState:UIControlStateNormal
                                      barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:barButton_land forState:UIControlStateNormal
                                      barMetrics:UIBarMetricsLandscapePhone];