SWRevealViewController from the right side on swift

前端 未结 6 2279
梦毁少年i
梦毁少年i 2021-02-20 05:28

I am using SWRevealViewController library to make a slide out menu in swift, but I am struggling to put this menu in the right side. I have seen on the library description this

6条回答
  •  长发绾君心
    2021-02-20 06:11

    For menu from right side,

    menuButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))

    For those who are looking for localization and support for RTL/LTR Languages.

    All you need to do is, when you create a new localization file, select the option "Interface builder Storyboard" instead of "Localizable string". It will create another storyboard for that language, and it's okay to do this cuz as far as I know, you'll use it only for Arabic language.

    Now in the new storyboard rename the segue to "sw_right" and in the old one let it be "sw_rear".

    When in your viewDidLoad() for the menu button, simply check for the current locale language

    let language = NSLocale.preferredLanguages[0] , and open menu from either side depending on your choice.

    This is my piece of code:

    if self.revealViewController() != nil {
    
                menuButton.target = self.revealViewController()
    
                let language = NSLocale.preferredLanguages[0]
    
                if language == "ar-AE" || language == "ar-US" || (language.range(of: "ar-") != nil) {
                    menuButton.action = #selector(SWRevealViewController.rightRevealToggle(_:))
                }
                else {
                    menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
                }
    
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    
            }
    

    You may also use the region code as I've noticed that the user may change language or the region individually.

    let region = NSLocale.current.regionCode
    

提交回复
热议问题