As of iOS 11, Apple has added Large Title Display Mode for UINavigationBar and UINavigationItem which makes an effect like this:
We could simply turn this effect on using the following Swift code:
navigationBar.prefersLargeTitles = true
My question is how we can make the large title right to left to be usable for Eastern right to left languages?
Thanks in advance.
I use this approach :
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.subviews[1].semanticContentAttribute = .forceRightToLeft
}
Well, it should be auto RTL for all RTL languages. All you have to do is to set a device language as one of RTL languages. Or, if you debug this in simulator, you can use on of Instruments Xcode is delivered with to simulate RTL while you are actually using LTR language
Related
I am using googlecast example.
When I show GCKUIExpandedMediaControlsViewController, all the buttons are in the correct position.
But when I use this part of the code, the buttons overlap each other.
UIView.appearance().semanticContentAttribute = .forceRightToLeft
I don't know if this is important, but the language in the iPhone settings - English.
This is the result that I get
We don't support RTL well now. You can file a feature request here https://developers.google.com/cast/support
I have an application with two languages: Arabic & English. I would like to change UI direction after changing the language inside the app.
I use this code to do this:
UIView.appearance().semanticContentAttribute = isRTL ? .forceRightToLeft : .forceLeftToRight
This code is working well, I will get UI with the correct direction, but the app performance is going worse. I have some lagging while selecting tabs on my Tab View Controller.
Any ideas on how to fix it? (removing changing semanticContentAttribute fix this problem, but I have to use this code for supporting Arabic language)
I am currently working on Localization. I have my app in English and Arabic. When I change the Language to Arabic all object goes to right, but there are few objects that i want them to be in left. Could please tell how to disable that function on a specific object?
Try setting the semanticContentAttribute property for the particular view to forceLeftToRight
someView.semanticContentAttribute = .forceLeftToRight
You can find more about it semanticContentAttribute in apple docs
I am creating an app that will be in English and Arabic. I am using my own localization system because I want to allow users to switch languages themselves from within the app and while the app is running (I am not aware of a way how to do this official Apple way). I would like to switch entire app to right-to-left when user picks arabic language, i.e. switch trailing and leading, text alignment etc.
Is this even possible?
EDIT: I am targeting iOS 7+
Yes, this is possible. From what I am understanding you want to move all of your components to the opposite side and also the text should be written from the right, right?
First of all, you have to set your language to the "AppleLanguage" key in user defaults:
NSUserDefaults.setObject(["ar"], forKey: "AppleLanguage")
Then you have to use auto layout. By default auto layout detects the region depending on the language chosen and when you've set leading and trailing spaces correctly, it will change the position of your text fields for example. If you want some of your components to stay on the same place, you have to use "left" instead of "leading".
If you need to change the direction of app to LTR & RTL then you could use that solution.
//FOR RIGHT TO LEFT
UIView.appearance().semanticContentAttribute = .forceRightToLeft
//FOR LEFT TO RIGHT
UIView.appearance().semanticContentAttribute = .forceLeftToRight
Hope this will solve your problem.
Reference: https://stackoverflow.com/a/48963618/8809657
As per apple documentation
"iOS doesn’t automatically mirror controls, so if you want this behaviour for an iOS app, subclass the control and override the drawing methods."
I want to mirror my whole UI when the user selects the language as Arabic or hebrew in the home screen. i was searching for tutorials and documentation for the same but nothing helps.
Please find what i have done till now:
am using Xcode 6.1 and the app targets from iOS 7 to iOS 8.1.
Autolayout is enabled and am not using left or right constraints. am using only leading or trailing constraints.
Base internationalisation is enabled in project settings also have added the languages in localization. but when am running the app in device and set device language and region to arabic i cant get the mirrored UI. Do i have to do anything in code to get the mirrored UI?
What is the best way to support RTL based UI? How to subclass control and override drawing methods?
Please use this link to get the sample screenshot of my app.
I just found a easy way from Apple documentations instead of having 2 storyboards for RTL and LTR languages.
First of all enable Base internationalisation in project settings
Add your language - in my case i have added arabic and hebrew
xCode will localize your stroy boards and you can see different storyboard strings for different languages
Change the texts for your labels in the newly created strings file. In my case i changed in arabic and hebrew string files
Use AutoLayout for designing the whole UI.
Don't use Left or right constraints. Instead of use only leading and trailing constraints
Add the below code in your main function and run the app in simulator
NSArray* languages = [NSArray arrayWithObjects:#"ar", nil];
[[NSUserDefaults standardUserDefaults] setObject:languages forKey:#"AppleLanguages"];
Your app now will work for RTL language with mirrored UI without having 2 storyboards.
Note : if you are not setting the autolayout constraints correctly it wont work. However because of the new screens you have to learn to use auto layout.
in Swift
let languages = ["ar"]
UserDefaults.standard.set(languages, forKey: "AppleLanguages")