使用 UITabbaritem 作为 UIButton

发布于 2024-08-24 14:11:59 字数 99 浏览 4 评论 0原文

有没有办法将 UITabbaritem 用作 UIButton? 我正在尝试制作一个标签栏,其项目不会改变视图。只是希望他们在同一个视图控制器中执行简单的操作。

谢谢。

Is there a way to use UITabbaritem as a UIButton?
I am trying to make a Tabbar that its items don't change the view. Just want them to do simple actions in the same view controller.

Thanks.

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

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

发布评论

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

评论(3

想你只要分分秒秒 2024-08-31 14:11:59

通过创建 UITabBarDelegate 并实现正确的方法,这可能是可能的,但这样做会违反 Apple 的 HIG 并导致您的应用被拒绝。 UIToolbar 是用于您所描述内容的正确类。来自该文档:

标签栏使用户能够
在不同模式或视图之间切换
在应用程序中,用户应该
能够访问这些模式
应用程序中随处可见。
然而,标签栏不应该
用作工具栏,其中包含
作用于元素中的按钮
当前模式(有关更多信息,请参阅“工具栏”
工具栏上的信息)。

It's probably possible, by creating a UITabBarDelegate and implementing the correct methods, but doing so would violate Apple's HIG and cause your app to be rejected. UIToolbar is the correct class to use for what you're describing. From that doc:

A tab bar gives users the ability to
switch among different modes or views
in an application, and users should be
able to access these modes from
everywhere in the application.
However, a tab bar should never be
used as a toolbar, which contains
buttons that act on elements in the
current mode (see “Toolbars” for more
information on toolbars).

空心↖ 2024-08-31 14:11:59

不,它继承自 UIBarItems:NSObject。 UIButton继承自UIControl。

No. It inherits from UIBarItems:NSObject. UIButton inherits from UIControl.

提笔书几行 2024-08-31 14:11:59

试试这个

   UIButton *chatButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [chatButton setImage:[UIImage imageNamed:@"list.png"] forState:UIControlStateNormal];
        [chatButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
        chatButton.frame = (CGRect) {
            .size.width = 30,
            .size.height = 35,
        };
        UIBarButtonItem *barBackButton= [[UIBarButtonItem alloc] initWithCustomView:chatButton];
        [navigationItem setLeftBarButtonItem:barBackButton];

    NSArray *barItemArray = [[NSArray alloc]initWithObjects:navigationItem,nil];
    [navigationBar setItems:barItemArray];

try this

   UIButton *chatButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [chatButton setImage:[UIImage imageNamed:@"list.png"] forState:UIControlStateNormal];
        [chatButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
        chatButton.frame = (CGRect) {
            .size.width = 30,
            .size.height = 35,
        };
        UIBarButtonItem *barBackButton= [[UIBarButtonItem alloc] initWithCustomView:chatButton];
        [navigationItem setLeftBarButtonItem:barBackButton];

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