2012-05-08 12 views
2
私はこのスニペットを持つすべてのアプリのために戻って左のボタンナビゲーションバー用のSOTセット画像の背景をしようとしている

UINavigationバーボタンの背景画像のサイズ

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    float version = [[[UIDevice currentDevice] systemVersion] floatValue]; 
    if (version >= 5.0) 
    { 
     // iPhone 5.0 code here 
     UIImage *image = [UIImage imageNamed: @"btn_back.png"]; 
     image = [image stretchableImageWithLeftCapWidth:40.0f topCapHeight:0.0f]; 
     [[UIBarButtonItem appearance] setBackButtonBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

    } 
    return YES; 
} 

私はstretchableImageWithLeftCapWidthに異なる値をしようとしてきた。しかし、私は正しいサイズに背景画像を設定することができますどのように

enter image description here

:最良の結果は、このでしたか?

おかげ

答えて

3

stretchableImageWithLeftCapWidth:topCapHeight:は推奨されません。代わりにresizableImageWithCapInsets:を使用してください。

これは動作するはずです:あなたの助けを

UIImage *buttonImage = [[UIImage imageNamed:@"btn_back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 10, 1, 10)]; 
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
+0

感謝を! – theomen