iOS4不支持setRightBarButtonItems:animated:
的方法UINavigationItem
。
如何重写此代码以在栏中右侧添加2个按钮?
[viewController.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:helpButton, settingsButton, nil] animated:YES];
感谢
答案 0 :(得分:0)
您可以在将按钮的alpha添加到视图之前将其设置为0,然后将其值设置为1.0。
//..Create the buttons
//Make it invisible
helpButton.alpha = 0.0;
settingsButton.alpha = 0.0
//Add them to the navBar
[self.navigationController.navigationBar addSubview:helpButton];
[self.navigationController.navigationBar addSubview:settingsButton];
//Animate it to 1.0
[UIView animateWithDuration:0.3 animations:^(void) {
helpButton.alpha = 1.0;
settingsButton.alpha = 1.0
}];
答案 1 :(得分:0)
如果要在iOS4中显示多个按钮,则必须手动创建它们。
例如,您可以将titleView设置为自定义视图,并通过覆盖ViewController的setTitle来执行您想要的任何操作:
- (void)setTitle:(NSString *)title
{
UIView *titleView = (UIView *)self.navigationItem.titleView;
if(!titleView)
{
titleView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 40.0)];
titleView.backgroundColor = [UIColor greenColor];
self.navigationItem.titleView = titleView;
}
}
您需要使用UIButton
代替UIBarButtonItem
。