菜鸟教程小白 发表于 2022-12-12 16:18:41

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


                                            <p><p>我的 UITabBar 中有 3 个项目,我的应用程序运行 2 种语言(英语和阿拉伯语)。当应用程序切换到阿拉伯语时,我需要更改项目的位置,因为需要从右到左阅读 <a href="/image/D7lQx.png" rel="noreferrer noopener nofollow"><img src="/image/D7lQx.png" alt="TabBar Items"/></a> </p>

<p>即。名为“One Way”的选项卡必须出现在右侧,Multi City 必须出现在左侧。有没有办法做到这一点?</p>

<p>我试过这个方法,但不允许</p>

<pre><code> UITabBarItem *realItemOne=;
    UITabBarItem *realItemTwo=;
    UITabBarItem *realItemThree=;

    if (_isEnglish) {
      self.tabBar.items=[ initWithObjects:realItemOne,realItemTwo,realItemThree, nil];
    }
    else{
      self.tabBar.items=[ initWithObjects:realItemThree,realItemTwo,realItemOne, nil];
    }
</code></pre>

<p>也试过了</p>

<pre><code>self.tabBar.items=[ allObjects];
</code></pre>

<p>我尝试的另一种方法</p>

<pre><code>UIViewController *viewControllerOne=;
    UIViewController *viewControllerTwo=;
    UIViewController *viewControllerThree=;
    if (_isEnglish) {
      NSArray *englishOrder=[ initWithObjects:viewControllerOne,viewControllerTwo,viewControllerThree, nil];
      ;
    }
    else{
      NSArray *arabicOrder=[ initWithObjects:viewControllerThree,viewControllerTwo,viewControllerOne, nil];
      ;
    }
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>不要更改项目,只更改选项卡项的文本和图像。</p>

<pre><code>if (_isEnglish) { change just image and text on 0. and 2. tab } else { also just change image and text }
</code></pre>

<p>当用户点击项目时,您检查语言,然后执行适当的方法。如果用户点击 0. 元素并且语言是英语,则调用 oneWay 方法,如果语言是阿拉伯语,则调用 multiCity</p>

<p>我希望这会有所帮助。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何根据应用程序中的某些情况以编程方式更改 UITabBarItems 的位置,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/32736499/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/32736499/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何根据应用程序中的某些情况以编程方式更改 UITabBarItems 的位置