UINavigationBar iphone 中 setBackBarButtonItem 中的 UIImage

发布于 2024-10-20 19:04:58 字数 605 浏览 3 评论 0原文

我在导航栏的 BackBarButtonItem 中添加图像,图像进入按钮,但图像未缩放以填充可能出现的问题。

这是我正在使用的代码,它以以下方式显示。

UIImage *backImage = [UIImage imageNamed:@"back.png"];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
[self.navigationItem setBackBarButtonItem: newBackButton];
[newBackButton release];
[backImage release];

在此处输入图像描述

实际上它应该如下图所示。

在此处输入图像描述

谢谢!

I am adding image in BackBarButtonItem of navigation bar, image gets in button but image is not scale to fill what would be the issue.

Here is the code i am using and it displays in following way.

UIImage *backImage = [UIImage imageNamed:@"back.png"];
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
[self.navigationItem setBackBarButtonItem: newBackButton];
[newBackButton release];
[backImage release];

enter image description here

Actually it should look like, below image.

enter image description here

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贩梦商人 2024-10-27 19:04:59
[self.navigationItem setHidesBackButton:YES];
[self.navigationItem setLeftBarButtonItem:newBackButton];

试试这个:)!

[self.navigationItem setHidesBackButton:YES];
[self.navigationItem setLeftBarButtonItem:newBackButton];

Try this :)!

自控 2024-10-27 19:04:59
problem is your image size.check it!
You can also use

//custom back button
    button =  [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];

    [button addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [button setFrame:CGRectMake(-2, 0, 52, 30)];



    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = btnItem;
    [btnItem release];
}
problem is your image size.check it!
You can also use

//custom back button
    button =  [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];

    [button addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [button setFrame:CGRectMake(-2, 0, 52, 30)];



    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = btnItem;
    [btnItem release];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文