gpt4 book ai didi

ios - 如何根据应用程序中的某些情况以编程方式更改 UITabBarItems 的位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:57:39 24 4
gpt4 key购买 nike

我的 UITabBar 中有 3 个项目,我的应用程序运行 2 种语言(英语和阿拉伯语)。当应用程序切换到阿拉伯语时,我需要更改项目的位置,因为需要从右到左阅读 TabBar Items

即。名为“One Way”的选项卡必须出现在右侧,而 Multi City 必须出现在左侧。有办法吗?

我试过这个方法,但是不允许

 UITabBarItem *realItemOne=[self.tabBar.items objectAtIndex:0];
UITabBarItem *realItemTwo=[self.tabBar.items objectAtIndex:1];
UITabBarItem *realItemThree=[self.tabBar.items objectAtIndex:2];

if (_isEnglish) {
self.tabBar.items=[[NSArray alloc] initWithObjects:realItemOne,realItemTwo,realItemThree, nil];
}
else{
self.tabBar.items=[[NSArray alloc] initWithObjects:realItemThree,realItemTwo,realItemOne, nil];
}

也试过这个

self.tabBar.items=[[self.tabBar.items reverseObjectEnumerator] allObjects];

我试过的另一种方法

UIViewController *viewControllerOne=[self.tabBarController.viewControllers objectAtIndex:0];
UIViewController *viewControllerTwo=[self.tabBarController.viewControllers objectAtIndex:1];
UIViewController *viewControllerThree=[self.tabBarController.viewControllers objectAtIndex:2];
if (_isEnglish) {
NSArray *englishOrder=[[NSArray alloc] initWithObjects:viewControllerOne,viewControllerTwo,viewControllerThree, nil];
[self.tabBarController setViewControllers:englishOrder];
}
else{
NSArray *arabicOrder=[[NSArray alloc] initWithObjects:viewControllerThree,viewControllerTwo,viewControllerOne, nil];
[self.tabBarController setViewControllers:arabicOrder];
}

最佳答案

不要更改项目,仅更改选项卡项目的文本和图像。

if (_isEnglish) { change just image and text on 0. and 2. tab } else { also just change image and text }

当用户点击该项目时,您检查语言然后执行适当的方法。如果用户点击 0.element 并且语言为英语,则调用 oneWay 方法,如果语言为阿拉伯语,则调用 multiCity

希望对您有所帮助。

关于ios - 如何根据应用程序中的某些情况以编程方式更改 UITabBarItems 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32736499/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com