本文介绍了添加到navigationItem.titleView时的UIButton样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在UINavigationItem titleView
中添加一个按钮(实际上是在UINavigation Bar的中心。
I need to add a button to the UINavigationItem titleView
(actually to the center of the UINavigation Bar.
我使用以下代码来完成:
I've used the following code to accomplish so:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(0, 0, 70, 30);
[btn setSelected:YES];
[btn setTitle:@"list" forState:UIControlStateNormal];
我已经执行以下操作:
我需要给出相同的风格完成按钮( UIBarButtonItem
)到按钮列表?
I need to give the same style of the "Done" button (which is UIBarButtonItem
) to the button "list"?
推荐答案
你可以使用UISegmentedControl:
You can use UISegmentedControl:
UISegmentedControl *mySegmentedControl = [[UISegmentedControl alloc]
initWithItems:@"Example"]];
mySegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[mySegmentedControl addTarget:self action:@selector(myMethod)
forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = mySegmentedControl;
这篇关于添加到navigationItem.titleView时的UIButton样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!