【发布时间】:2014-09-11 05:45:39
【问题描述】:
我有一个 UIToolbarButton,它有一个 UIButton 来保存图像。现在,当我点击这个 UIToolbarButton 时,我想在当前视图中打开另一个视图。
我的代码:
- (IBAction)btnNowPlaying:(id)sender
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(openPlaying:)];
[self.view addGestureRecognizer:tap];
}
- (void)openPlaying:(UIGestureRecognizer *)sender
{
NewMainViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Center"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * npvc = [storyboard instantiateViewControllerWithIdentifier:@"NowPlayingVC"];
[vc.containerView addSubview:npvc.view];
}
这个动作,btnNowPlaying 在 UIButton 上。
【问题讨论】:
-
为什么不直接使用 UIBarButton 项的 image 属性,而不是在条形按钮内放置一个 UIButton?
-
如果我使用图像属性,图像不显示
-
只显示 Tint 颜色
-
真的吗?这个对我有用。确保您的图片尺寸合适。
-
图片尺寸为 87X82 像素
标签: ios uitapgesturerecognizer uitoolbaritem