简体   繁体   English

向底部工具栏添加按钮

[英]adding buttons to a bottom toolbar

I have the following code: 我有以下代码:

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

Why I cannot see toolbar buttons? 为什么我看不到工具栏按钮? What's the problem? 有什么问题?

What meggar says is probably the right answer. 麦加说的可能是正确的答案。 Try doing it this way. 尝试以这种方式进行。

--UPDATE-- Since the problem still exists I have updated the example to move the set call to the view controller instead of the navigation controller. -更新-由于问题仍然存在,因此我更新了示例,将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