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")
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've just moved from android to iOS with swift.
android provides tools namespace that supports this kind of requirement. I just use tools:text="fake string" so that the string only appears on the IDE screen.
When it comes to iOS storyboard, while I'm drawing layout with storyboard, one question is remaining in my mind.
Can I have a fake string that only appears on the storyboard but not on iOS screen?
Please let me know if I can use the same feature in iOS programming.
No, there is no fake text available. The text which you are setting in storyboard for a label will display while you are running the application. You can create reset/change this text in viewDidLoad of the corresponding view controller by creating an outlet of the label. Like
self.label.text = "New text"
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
I'm using xcode 6 with storyboard for ios app development.
I have a problem with UILabel in view controllers in storyboard: the text is simple and inlower case, but when I run the app in the simulator or in the device I see the Label text in UPPERCASE.
Labels have no outlets, and cannot be modified programmatically.
some one has a solution? I'd prefer not using IBOutlet and setting text by code..
I had somewhat similar problem. In my case everything(title, lables, button texts, etc.) was in upper case. I found out that "Localization Debugging" was on, so when I had language on iphone which was not supported by localization, it turned words automatically to upper case. When I disabled it, everything worked fine again.
Just go to "Product > Scheme > Edit Scheme" and there select "Run" and disable "Localization Debugging". (Sorry, I don't have enough reputation to post images, otherwise I would put here screen)
Hope it helps
I answer myself fot other people.
Nothing to do with this strange thing. It seems a xcode bug. Sometimes the labels appears uppercased, other times are ok.
I discover a trick that was using the attributed text in storyboard. in this way it works correctly.
Another way is to use a outlet and setting the uilabel.text by code.
Bye
The first image is when the language is set to Hebrew, the second is in English. Look at the word " Thanks: " in the image. How Waze managed to change the location of the word to a Right To Left language? With regular localization
Thanks:x
should have been
תודות:X
That's just one example. Waze does that a lot.
Waze supports iOS 4.3 and later so AutoLayout is out of the question. With regular localization I know you can change the content of the word but location? that's a first.
Can I set an if iphone language is English then change the layout to..? (if so that's a lot of ifs.."
Thanks
Frankly, I do not know if there is any standarized way of doing that.
But I see several options:
1. Using localized .xib files or even full storyboards.
2. Changing that programmatically. Get the current localization and add some IFs to the view controller and re-arrange the items. If this is in a custom UITableViewCell subclass then overwrite the layoutSubViews (or so) and change the layout accoring to the locale settings. If you layout it within cellForRowAtIndexPath then apply the localization there.