如何使 leftBarButtonItem 看起来像 backBarButtonItem?

发布于 2024-12-04 09:57:54 字数 184 浏览 1 评论 0原文

默认解决方案不合适:

  1. 要更改以前的 ViewController 标题 - 我需要创建自己的函数来控制按钮触摸
  2. 以创建 leftBarButtonItem 并隐藏 backBarButtonItem - leftBarButtonItem 看起来不像默认的 backBarButtonItem。

The default solvings are not appropriate:

  1. to change the previous ViewController title - I need to make my own function controlling the button touches up
  2. to make a leftBarButtonItem and hide backBarButtonItem - leftBarButtonItem doesn't look like a default backBarButtonItem.

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

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

发布评论

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

评论(4

一念一轮回 2024-12-11 09:57:54

这是一个创建自定义 leftBarButtonItem 的示例:

UIImage *buttonImage = [UIImage imageNamed:@"backbutton.png"];
UIButton *aButton = [UIbutton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
aButton.frame = CGRectMake(0.0,0.0,buttonImage.size.width,buttonImage.size.height);
[aButton addTarget:self action:@selector(aSelector) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];
self.navigationItem.leftButtonItem = backButton;

希望它有帮助...

编辑:

试试这个...

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"yourimage.jpg"] style:UIBarButtonItemStyleBordered target:self action:@selector(aSelector)];
self.navigationItem.leftBarButtonItem = backButton;

我不记得后退按钮是什么类型的按钮,尝试将默认样式更改为其他。祝你好运!

Here's an example to create a custom leftBarButtonItem:

UIImage *buttonImage = [UIImage imageNamed:@"backbutton.png"];
UIButton *aButton = [UIbutton buttonWithType:UIButtonTypeCustom];
[aButton setImage:buttonImage forState:UIControlStateNormal];
aButton.frame = CGRectMake(0.0,0.0,buttonImage.size.width,buttonImage.size.height);
[aButton addTarget:self action:@selector(aSelector) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:aButton];
self.navigationItem.leftButtonItem = backButton;

Hope it helps...

Edit:

Try this...

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"yourimage.jpg"] style:UIBarButtonItemStyleBordered target:self action:@selector(aSelector)];
self.navigationItem.leftBarButtonItem = backButton;

I don't remember what type of button is the backbutton, try to change the default style to other. Good luck!

七堇年 2024-12-11 09:57:54

只需创建一个自定义 barbuttonitem 并使用类似于后退按钮项目的图片对其进行自定义即可。
您可以从导航堆栈中的视图控制器获取其文本。

然后处理水龙头以实现所需的效果

Just create a custom barbuttonitem and customize it with a picture similar to the back button item.
You can get its text from the view controllers in the navigation stack.

Then handle the taps to implement the desired effect

单调的奢华 2024-12-11 09:57:54

您可以将自定义视图指定为导航控制器的栏按钮,如下所示:

UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:yourCustomizedControl];
[yourCustomizedControl release];

self.navigationItem.leftBarButtonItem = customItem;
[customItem release];

检查 此 Apple 文档 以获取更详细的说明。

You can assign your custom views as the bar buttons to your navigation controller, like this:

UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:yourCustomizedControl];
[yourCustomizedControl release];

self.navigationItem.leftBarButtonItem = customItem;
[customItem release];

Check this Apple documentation for a more detailed explanation, if you want.

零度° 2024-12-11 09:57:54

这是添加类似后退按钮的技巧:

UINavigationItem* backNavigationItem = [[UINavigationItem alloc] initWithTitle:@"Back"];
[_navigationBar pushNavigationItem:backNavigationItem animated:NO];
[backNavigationItem release];

您可以通过这种方式添加更多项目(例如标题、右键):

UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Title"];
navigationItem.rightBarButtonItem = // Some UIBarButtonItem
[_navigationBar pushNavigationItem:navigationItem animated:NO];
[navigationItem release];

Here is a hack to add a back-like button:

UINavigationItem* backNavigationItem = [[UINavigationItem alloc] initWithTitle:@"Back"];
[_navigationBar pushNavigationItem:backNavigationItem animated:NO];
[backNavigationItem release];

You can add more items (such like title, right button) this way:

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