我想在UINavigator控制器中添加2个按钮 我首先尝试创建一个按钮,然后将其添加到UIToolbar但却无法使其工作。
这是我想要的图像:)
任何帮助将不胜感激
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
addButton.frame = CGRectMake(40, 40, 44, 44);
[addButton setTitle:@"YES" forState:UIControlStateNormal];
[addButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)];
NSArray* buttons = [NSArray arrayWithObjects:self.editButtonItem, addButton, nil];
[toolbar setItems:buttons animated:NO];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
}
- (IBAction)buttonClicked:(id)sender
{
NSLog(@"Hi!");
}
答案 0 :(得分:0)
你可以这样做:
self.navigationItem.rightBarButtonItem = toolbar;