iphone - 将按钮添加到底部工具栏

标签 iphone objective-c ios uinavigationcontroller

我有以下代码:

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/

相关文章:

iphone分辨率问题

ios - ios-ntp框架同步问题

iphone - IOS5 中的本地通知 - 如何让它在屏幕上弹出而不是在通知中心?

ios - 如何在 iPhone 上进行选择 View

iOS 使用 mask 和 UIColor 创建 UIImage

iphone - 解释一下 leftBarButtonItem、rightBarButtonItem、titleView 的边距逻辑

iOS:将两个 UIButton 合并为一个 UIButton

iphone - UIButton 作为 UITextfield 的 subview

iphone - JSON 响应显示在警报 View 中?

ios - 使用密码或密码保护 CoreData DB 的正确方法是什么?