iOS4 不支持setRightBarButtonItems:animated:
a的方法。UINavigationItem
我如何重写此代码以在栏右侧添加 2 个按钮?
[viewController.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:helpButton, settingsButton, nil] animated:YES];
谢谢
iOS4 不支持setRightBarButtonItems:animated:
a的方法。UINavigationItem
我如何重写此代码以在栏右侧添加 2 个按钮?
[viewController.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:helpButton, settingsButton, nil] animated:YES];
谢谢
您可以在将按钮添加到视图之前将其 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
}];
如果要在 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;
}
}
而且您需要使用 aUIButton
而不是UIBarButtonItem
.