菜鸟教程小白 发表于 2022-12-11 20:39:55

iOS 在 UINavigationController 项中显示箭头后退按钮


                                            <p><p>我想在单击 UINavigationController 项上的后退按钮时收到通知。所以,我创建了一个自定义 UIBarButtonItem</p>

<pre><code>UIBarButtonItem *leftBarButton = [ initWithTitle:NSLocalizedString(@&#34;SettingsTabTitleKey&#34;, @&#34;&#34;) style:UIBarButtonItemStyleBordered target:self action:@selector(settingsButtonPushed:)];
    self.navigationItem.leftBarButtonItem = leftBarButton;
</code></pre>

<p>但是,显示的按钮是矩形的,不像其他后退按钮那样有箭头。无论如何,我可以显示正确的后退按钮或任何可以找到 .png 的地方吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>为了保留箭头样式的按钮,我通常这样做:</p>

<pre><code>self.navigationItem.backBarButtonItem = myCustomUIButton;
</code></pre>

<p>而不是设置 leftBarButtonItem。</p>

<p>但是,这必须在 ViewController 的 viewDidLoad: 方法中完成,该方法将 ViewController 推送到您希望按钮出现的位置。所以你在按下下一个 ViewController 之前设置后退按钮......</p>

<p>您还可以通过在 ViewController 的 viewWillDisappear: 方法中添加一些行为来获得按下后退按钮的通知。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iOS 在 UINavigationController 项中显示箭头后退按钮,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/8390360/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/8390360/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS 在 UINavigationController 项中显示箭头后退按钮