gpt4 book ai didi

iphone - 向导航栏添加按钮

转载 作者:行者123 更新时间:2023-12-03 20:18:12 25 4
gpt4 key购买 nike

是否可以使用IPhone SDK向导航栏添加按钮?

我的导航栏中已经有 2 个按钮,分别为 leftBarButton 和 rightBarButton。我还需要 2 个按钮。如何实现?

我不需要将它们包含在导航栏本身中。但由于该应用程序只包含一个表,我认为它不能在其他地方给出。

最佳答案

您可以使用UISegmentedControl 。检查UICatalog代码示例以检查其在导航栏中的用法。

这里是一些示例代码:

       - (void)viewDidLoad {
[super viewDidLoad];

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
[UIImage imageNamed:@"up.png"],
[UIImage imageNamed:@"down.png"],
nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 90, 35);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;

UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];

self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
}

- (void)segmentAction:(id)sender{

if([sender selectedSegmentIndex] == 0){
//do something with segment 1
NSLog(@"Segment 1 preesed");
}else{
//do something with segment 2
NSLog(@"Segment 2 preesed");
}
}

关于iphone - 向导航栏添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1900252/

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