使用UIBarButtonItemStyle创建UIBarButtonSystemItem

时间:2011-09-08 16:11:02

标签: iphone ios uinavigationbar uibarbuttonitem uibarbuttonitemstyle

我想创建一个系统UIBarButton,但我希望它有简洁的风格 我试过这个代码,但样式被忽略了。 怎么了?

UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearch)];    
search.style = UIBarButtonItemStylePlain;
self.navigationItem.rightBarButtonItem = search;
[search release];

2 个答案:

答案 0 :(得分:2)

这里最重要的是你需要将你的按钮放在前一个控制器中,而不是放在要推动的控制器中。

//Your actual ViewController
UIBarButtonItem *search = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearch)];    
search.style = UIBarButtonItemStylePlain;
self.navigationItem.rightBarButtonItem = search;
[search release];

//Controller that is going to be pushed and will display the new UIBarButtonItem
[self.navigationController pushViewController:newViewController animated:YES];

答案 1 :(得分:0)

找到类似的帖子here

制定此计划的方法似乎是创建自定义UIButton并将其分配给栏按钮。