I localized my back button images in navigation bars for English(<) and Arabic(>) in my app. When system language is set to Arabic, in iOS 9 and later, iOS will flip the navigation bar automatically and the back button will be on the right, so ">" image is a perfect direction. However, the back button is still on the left in iOS 8, and in this case ">" will be pretty weird. Can I use image that is localized for other language in my code? Any suggestion is appreciated.
2
votes
2 Answers
2
votes
0
votes
For RTL support for button icons you need to provide the image at run time like:
//MARK: - Locale identifiers
enum LOCALE_IDENTIFIERS: String {
case arabic = "ar-SA"
case hindi = "hi"
case urdu = "ur"
case english = "en"
}
CURRENT_LANGUAGE = LOCALE_IDENTIFIERS.urdu.rawValue
/* Assume the CURRENT_LANGUAGE will return the current selected language */
/*This is what you need. The above code is just for making the sense*/
var iconName = ""
if Locale.characterDirection(forLanguage: CURRENT_LANGUAGE) == Locale.LanguageDirection.rightToLeft {
iconName = "ic_back_button_RTL"
}else {
iconName = "ic_back_button_LTR"
}
let backButtonImage: UIImage = UIImage(named: iconName)!
//Use this backButtonImage for your button.
/*The "ic_back_button_RTL" is an icon like: -> */
/*The "ic_back_button_LTR" is an icon like: <- */