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
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