UIView layout Localization using Autolayout - ios

I would like to make an app using autolayout, such that when a device is configured in a right-to-left (RTL) language, the NSLayoutConstraints reverse the order of two views. I'm building the views programatically, without Interface Builder.
I am using leading and trailing constraints, and expect view A to be on the left and view B to be on the right. Once in RTL, I expect that order to be reversed, so that A is to the right of B.
I have added the RTL language to the localization list in the project Info tab.
Maybe I'm missing some project configuration. Where do I need to add the RTL language so that the project switches its layout according to the device language?
Note - I did try to change the "Localization native development region" in the Info.plist from "en" to an RTL language, and the constraints flipped. But this is not a solution because in this case it will always be flipped, even if the device language is in english.
Thanks in advance!

Related

Mirror programming for uicontrols in xcode

I am new to multi-language app.
What I am doing is,
an app with two languages.
English & Arabic
The language of the app depends upon the device language.
(I want to change this too, that app language should be controlled from inside the app. not device dependant but thats next question)
I am having some controls like UIButton,UITextField,UILabel, etc....
When my app is in English I gave these controls frame starting from left corner of device, and when my app is in Arabic I gave them frames starting from Right corner of device. (As arabic is written from Right - to - left)
My Question is,
For this purpose I need to do extra work,
i.e. check device language and then set the frames of control.
on each view I may have "n" number of controls, and giving the frame sizes to all controls for both language doesn't seems good from my view.
Is there anything available in Xcode itself by using which I can do this.
means I need to give frames for default language (i.e. English) and if my device language is change to Arabic then frames of Controls will be automatically Mirrored from Right to left.
Following screens may give some idea.
(I used different frames for all those controls checking device language)
Any help is accepted.
Thanks in advance.
sorry If question is asked already. But I didn't find anything.
If anyone found then link to that is Welcome :)
From Supporting Right-to-Left Languages:
Your user interface should be mirrored when displaying right-to-left languages. If you use base internationalization and Auto Layout, most of the user interface will appear mirrored automatically for you. The text direction changes to right-to-left with the exception of phone numbers and country codes which are always left-to-right. Some views and controls in your user interface may not change direction automatically which you can fix programmatically.
They functionality you're looking for is called Auto Layout which was introduced a few years ago by Apple. It will handle lots of things you need, but there's also a lot to do for you. The guide above will guide you through the necessary steps.
Update from iOS 9.0:
iOS 9 brings comprehensive support for right-to-left languages, which makes it easier for you to provide a flipped user interface. For example:
Standard UIKit controls automatically flip in a right-to-left context.
UIView defines semantic content attributes that let you specify how particular views should appear in a right-to-left context.
UIImage adds the imageFlippedForRightToLeftLayoutDirection method, which makes it easy to flip an image programmatically when appropriate.
To learn more about providing a flipped user interface, see Supporting Right-to-Left Languages.

Convert my xib to arabic language

My app is going to be made in both English, Arabic languages. I have made my xib using auto layout for english version. Now i want to use same xib for arabic version. But the problem is that interface will also change its layout from right to left.
I know about NSLocalization for xib's but i am clueless for arabic version, I googled last day but not found any thing relevant.
e.g. English version
Icon label
Arabic version
label Icon
Please put some light in how can i convert my english version of xib to be used in Arabic version.
Thanks
Use Auto Layout in your xibs. By default, the constraints created in Xcode's Interface Builder use Leading/Trailing properties, meaning all of the UI gets automatically flipped in RTL languages.
Like Leszek commented as well, you can check out Supporting Right-to-Left Languages for anything else.

Autolayout with localization without restarting the app

My app supports both Arabic and English version and Autolayout handles alignment of text and UI elements. But a feature I need to add is a language switch button that immediately changes the language. I even need autolayout to adjust as per the language but doesn't seems to take effect unless the app is restarted. Any suggestions how to achieve this functionality.

previewing autolayout with different sizes and language styles

I've started learning the new Auto Layout stuff in XCode on iOS. Auto Layout is actually quite neat, but it appears to be a pain to test. I seem to remember on the Mac side there was a way you could Preview an interface and drag it to different sizes to test if controls lined up properly. Is there anything like this for iOS or some tool to facilitate testing your AutoLayout views? Additionally, something to switch to Right to Left would be useful too. I just want to test all my constraints and make sure they're perfect.
To view a preview of what Auto Layout will do under different conditions, do the following in Xcode 5:
Open up a storyboard.
Open the assistant editor (as many as you want).
In the assistant editor, tap the 4th button (the one that says Manual/Automatic/etc).
Choose "Preview".
You can now use the controls on the bottom right to customize:
the iOS version (6 or 7)
device rotation (portrait or landscape)
device screen size (3.5" or 4")
To simulate a right-to-left language, according to the WWDC 2012 Auto Layout by Example (Session 232) video:
Set the following arguments: (using a method such as this)
AppleTextDirection YES
NSForceRightToLeftWritingDirection YES
More arguments that can help with Auto Layout can be found here.
If you have localized strings, you can go to the Xcode Product menu then pick Scheme ---> Edit Scheme. In the top section on the right (Arguments Passed On Launch), click the + button and then type in: -NSDoubleLocalizedStrings YES and make sure the check box next to it is checked. This will double all your localized strings to simulate a language like German that tends to have long words.
Thanks to Apple we have the live preview in the new XCode 5.
One option for iOS i've found is to set Status Bar to None on root View of the XIB. This will remove the black status bar and show resize handles. This way you can drag the frame around and see how the controls behave. It still won't run code though. Also, I haven't found out how to enable Right-To-Left text yet.

How to make constant UI in English and Arabic in Blackberry?

I am making one application which can support English and Arabic language. My almost all code is done but now i am facing one problem that ,when i run application setting English language it looks great,but for arabic my UI get distrubed because English language has left allignment and Arabic has right allignment by default....what to do now ??please any one have idea then please help me.....waiting for reply
If it's about right align UI elements - use the Field.RIGHT style to have your components right align. It is left aligned by default. If you are using a HorizontalFieldManager you will also want to set the style for the scroll direction to be LEFTWARD.
To set the style pass in these in the components constructor OR'ed, so:
new myField(Field.RIGHT | Manager.LEFTWARD);
Use the Locale object to determine which language is currently set and set the alignment based on it.
APPROACH: Using third party library
Have a look at Arabic and English.
LWUIT UI library is pretty easy to create a common UI for both left-to-right and right-to-left languages. It might sound an uphill task now but going forward you will need to
support multiple ODM's
multipe screen device resolution
multiple flavors of VM, etc
LWUIT library resolves all these problems and to top it the library source code is licensed under GPLv2 with the classpath exception. This essentially means you can use this library in your commercial projects. It is supports most mordern Blackberry OS's.

Resources