自动突出显示 UITabBar 按钮

发布于 2024-10-08 18:07:21 字数 327 浏览 0 评论 0原文

我正在使用这种方法 http://redartisan.com/2010 /6/27/uisegmented-control-view-switching-revisited 创建自定义 UITabBar 并在单击某个 TabBarItem 时加载特定视图。

问题是最初加载第一个视图,但第一个选项卡栏项目未突出显示。有没有办法强制突出显示?我没有使用 tabbarcontroller,所以我无法使用它的方法。

I'm using this method http://redartisan.com/2010/6/27/uisegmented-control-view-switching-revisited to create a custom UITabBar and loading a particular view when a certain TabBarItem is clicked.

The problem is that initially the first view is loaded, but the first tab bar item is not highlighted. Is there a way to force the highlight? I'm not using the tabbarcontroller so I can't use its methods.

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

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

发布评论

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

评论(1

风轻花落早 2024-10-15 18:07:21

如果创建实例变量:UITabBar *tabBar;
属性:

@property (nonatomic, assign) IBOutlet UITabBar *tabBar;

并将此属性连接到 Interface Builder 中的 UITabBar,您可以使用:

for(UITabBarItem *tab in tabBar.items) {
    if ([tab.title isEqualToString: @"My Tab Title"]) {
        tabBar.selectedItem = tab;
        }
    }

如果所有选项卡都有唯一的标题(通常是这种情况),则此方法有效。

If you make an instance variable: UITabBar *tabBar;
a property:

@property (nonatomic, assign) IBOutlet UITabBar *tabBar;

and connect this property to the UITabBar in Interface Builder, you can use:

for(UITabBarItem *tab in tabBar.items) {
    if ([tab.title isEqualToString: @"My Tab Title"]) {
        tabBar.selectedItem = tab;
        }
    }

This works if all tabs have a unique title, which is normally the case.

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