2
votes

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
Please try if ([curruntLan isEqualToString:@"ar"]) { UIImage *img = [UIImage imageNamed:@"icoBack"]; img = [UIImage imageWithCGImage:img.CGImage scale:img.scale orientation:UIImageOrientationUpMirrored]; [self.btnBack setImage:img forState:UIControlStateNormal];Rajesh

2 Answers

2
votes

You don't need to have an extra image for these kinds Select a particular asset from properties select "Direction" previously it will be "fixed" convert it to "Left to Right, Mirrors"

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: <- */