点击 UIToolBar 中的按钮

发布于 2024-12-21 07:38:17 字数 381 浏览 2 评论 0原文

我有一个自定义 UIToolBar,左侧有一个按钮(图像),右侧有一个文本。当我点击按钮时,只有用于按钮的图像是可点击的,而不是工具栏的整个左侧部分。我是否需要有一个覆盖整个部分的图像才能使整个部分变得清晰?或者 UIToolBar 是否提供了任何方法来使整个项目可点击?

下面是在我的自定义类子类化 UIToolBar 中添加这些项目的代码:

[self setItems:[NSArray arrayWithObjects:AddBarButton, FlexibleSpaceBarButton, TextBarItem, nil]];

在此处输入图像描述

I have a custom UIToolBar with an button(image) on left and a text on right. When I tap on the button, only the image which I used for the button is tappable and not the entire left section of the toolbar. Do I need to have a image which covers the entire section to make the entire section tappale? Or is there any way which UIToolBar provides to make the entire item tappable?

Below is the code to add these items in my custom class subclassing UIToolBar:

[self setItems:[NSArray arrayWithObjects:AddBarButton, FlexibleSpaceBarButton, TextBarItem, nil]];

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生死何惧 2024-12-28 07:38:17

当您添加按钮时......只有该按钮是可点击的。要执行您想要的操作,您可以向视图添加手势识别器并以这种方式响应点击:

    UITapGestureRecognizer *gr;
    gr = [[UITapGestureRecognizer alloc]
             initWithTarget:self action:@selector(tapGesture:)];
    [yourView addGestureRecognizer:gr];
    [gr release];

当然,只有当您有一个包含按钮的“子视图”时,这才有效。

When you add a button ... only the button is tap-able. To do what you want, you could add a gesture recognizer to the view and respond to taps that way:

    UITapGestureRecognizer *gr;
    gr = [[UITapGestureRecognizer alloc]
             initWithTarget:self action:@selector(tapGesture:)];
    [yourView addGestureRecognizer:gr];
    [gr release];

Of course, this will only work if you have a "subview" that is containing your button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文