2012-05-08 33 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