我有以下代码:
self.shareButton=[[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 35, 35)];
[shareButton setBackgroundColor:[UIColor blueColor]];
[shareButton setBackgroundImage:[UIImage imageNamed:@"share_button"] forState:UIControlStateNormal];
[shareButton setBackgroundImage:[UIImage imageNamed:@"share_button_pressed"] forState:UIControlStateHighlighted];
[shareButton addTarget:self action:@selector(shareButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationController setToolbarItems:[NSArray arrayWithObject:shareButton] animated:YES];
为什么我看不到工具栏按钮?有什么问题吗?
最佳答案
meggar所说的可能就是正确的答案。尝试这样做。
--更新-- 由于问题仍然存在,我更新了示例,将 set 调用移至 View Controller 而不是导航 Controller 。
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:shareButton];
[self setToolbarItems:[NSArray arrayWithObject:barButtonItem] animated:YES];
[barButtonItem release];
关于iphone - 将按钮添加到底部工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8853910/