2

このコードを使用して iOS 5 用のバーボタンをカスタマイズしたところ、正しく機能しました。

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

iOS 5 でデバイスを横向きに回転すると、結果は次のようになります。

ここに画像の説明を入力

iOS 6 では、結果は次のようになります。

ここに画像の説明を入力

デバイスが横向きのときに画像のサイズを適切に変更するには、どうすればよいですか?

4

1 に答える 1

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];
于 2012-09-25T16:27:15.377 に答える