gpt4 book ai didi

iphone - 添加到 navigationItem.titleView 时的 UIButton 样式

转载 作者:行者123 更新时间:2023-12-03 19:32:00 27 4
gpt4 key购买 nike

我需要向 UINavigationItem titleView 添加一个按钮(实际上是 UINavigation Bar 的中心。

我使用以下代码来完成此任务:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0, 0, 70, 30);
[btn setSelected:YES];
[btn setTitle:@"list" forState:UIControlStateNormal];

我已经执行以下操作:

enter image description here

我需要为按钮“列表”提供相同样式的“完成”按钮(即 UIBarButtonItem)?

最佳答案

您可以使用 UISegmentedControl:

UISegmentedControl *mySegmentedControl = [[UISegmentedControl alloc]
initWithItems:@"Example"]];
mySegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[mySegmentedControl addTarget:self action:@selector(myMethod)
forControlEvents:UIControlEventValueChanged];

self.navigationItem.titleView = mySegmentedControl;

关于iphone - 添加到 navigationItem.titleView 时的 UIButton 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9299703/

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