我正在创建一个项目,我需要在导航栏左侧有一个默认后退按钮和自定义过滤器按钮。
我创建了自定义后退按钮、自定义过滤器按钮并将它们添加到 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.
最佳答案
您需要使用 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/