我使用此代码自定义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上将设备旋转到横向时,结果如下:
现在有了iOs 6,结果是:
当设备处于横向状态时,发生了什么以及如何正确调整图像大小?
答案 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];