ios - 在 LeftBarButtonItems ios 中使用自定义按钮创建默认后退按钮

标签 ios iphone swift uinavigationcontroller uibarbuttonitem

我正在创建一个项目,我需要在导航栏左侧有一个默认后退按钮自定义过滤器按钮

我创建了自定义后退按钮、自定义过滤器按钮并将它们添加到 leftBarButtonItems

navigationItem.leftBarButtonItems = alignedLeftBarButtonItems()

    func alignedLeftBarButtonItems() -> [UIBarButtonItem] {

            let filterButton = createLeftCustomBarButton()

            // back button creation
            let backButton = UIBarButtonItem(image: R.image.navBackArrow(), style: .plain, target: self, action: #selector(self.backButtonPressed(_:)))
            backButton.tintColor = UIColor.white

            let barButtonsItems = [
                backButton,
                UIBarButtonItem(customView: filterButton)
            ]
            return barButtonsItems
        }

一切都很好并且工作正常。

关注:

Default, User can go to the previous VC by sliding from left to right. This functionality is lost in making this. Is there a way I can have both buttons with the sliding functionality.

Nav Bar

最佳答案

您需要使用 UIBarButtonItem 来使用后退按钮的默认向左或向右滑动功能:

let backButton = UIBarButtonItem(image: Image.backButton, style: UIBarButtonItemStyle.plain, target: self, action: #selector(actionBackButton))
self.navigationItem.leftBarButtonItem = backButton

With Custom button, you cannot get this functionality

关于ios - 在 LeftBarButtonItems ios 中使用自定义按钮创建默认后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52160828/

相关文章:

arrays - swift 3 : How can I get the Array from the String

ios - 不使用 Storyboard的 UICollectionVIew?

ios - 如何在 Swift 中计算 SHA512/256 哈希值?

ios - 在飞行模式下,CTCarrier 中的 isoCountryCode 不返回 nil

iphone - "speed view"的本地声明隐藏了实例变量

iphone - 变量的类型不完整 'struct sockaddr_in'

IOS - CNContactPickerViewController 应该只显示有电子邮件的名字吗?

ios - Apple App 链接打不开,而是要求 itunes

ios - UISegmentedControl 重新加载特定页面

ios - 当需要根据特定键过滤用户帖子时如何构建(保存/检索)?