gpt4 book ai didi

iphone - UINavigationItem:再添加一个按钮

转载 作者:搜寻专家 更新时间:2023-10-30 19:52:30 27 4
gpt4 key购买 nike

enter image description here

如何在导航项中添加新按钮?假设我需要将其添加到右侧按钮附近。

用于左右的代码。

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_cancelButton];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_shareButton];

如何再添加一个按钮?

最佳答案

有不同的方法可以在导航 Controller 的右侧添加多个按钮。下面给出了一种最简单的方法

 UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];

UIButton *exampleButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
exampleButton1.frame = CGRectMake(0, 2, 30, 40);
[exampleButton1 addTarget:self action:@selector(FirstMethod) forControlEvents:UIControlEventTouchUpInside];
[exampleButton1 setImage:[UIImage imageNamed:@"image1.png"] forState:UIControlStateNormal];
[buttonView addSubview:exampleButton1];


UIButton *exampleButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
exampleButton2.frame = CGRectMake(70, 2, 30, 40);
[exampleButton2 addTarget:self action:@selector(Second method) forControlEvents:UIControlEventTouchUpInside];
[exampleButton2 setImage:[UIImage imageNamed:@"image2.png"] forState:UIControlStateNormal];

[buttonView addSubview:exampleButton2];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonView];

希望对您有所帮助,谢谢

关于iphone - UINavigationItem:再添加一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16440258/

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