【问题标题】:UINavigation bar button background image sizeUINavigationbar 按钮背景图片大小
【发布时间】:2012-05-08 16:48:17
【问题描述】:

我正在尝试使用这个 sn-p 为所有应用程序的左后退按钮导航栏设置图像背景:

- (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: 中尝试不同的值:但最好的结果是:

如何将背景图片设置为正确的尺寸?

谢谢

【问题讨论】:

    标签: objective-c ios5


    【解决方案1】:

    stretchableImageWithLeftCapWidth:topCapHeight: 已弃用。请改用resizableImageWithCapInsets:

    这应该可行:

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

    【讨论】:

      猜你喜欢
      • 2014-06-20
      • 2015-10-27
      • 1970-01-01
      • 1970-01-01
      • 2021-04-04
      • 2017-03-07
      • 2013-03-05
      • 2012-03-07
      • 1970-01-01
      相关资源
      最近更新 更多