繁体   English   中英

向底部工具栏添加按钮

[英]adding buttons to a bottom toolbar

我有以下代码:

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];

为什么我看不到工具栏按钮? 有什么问题?

麦加说的可能是正确的答案。 尝试以这种方式进行。

-更新-由于问题仍然存在,因此我更新了示例,将set调用移至视图控制器而不是导航控制器。

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:shareButton];
[self setToolbarItems:[NSArray arrayWithObject:barButtonItem] animated:YES];
[barButtonItem release];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM