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