gpt4 book ai didi

objective-c - UINavigationbar 按钮背景图片大小

转载 作者:行者123 更新时间:2023-12-04 05:47:25 25 4
gpt4 key购买 nike

我正在尝试使用此代码段为所有应用程序的左后退按钮导航栏设置图像背景:

- (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

如何将背景图像设置为正确的大小?

谢谢

最佳答案

stretchableImageWithLeftCapWidth:topCapHeight:已弃用。使用 resizableImageWithCapInsets:相反。

这应该有效:

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

关于objective-c - UINavigationbar 按钮背景图片大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10502869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com