How to shift all UIView From Left to Right in iOS? (Objective-C) -


i working on app support english , arabic languages.

my requirement when choose english, uiviews should displayed left right.
(ie. on left side there uiimageview , uilabel on right of uiimageview, see in pic below)

but when user choose arabic language uiimageview should come right side of screen , uilabel should come left of uiimageview.

is possible in ios or should create separte viewcontroller layout arabic language ????

here need change layout

enter image description here

there 2 ways of localisation,

  • localisation- can using single storyboard, have set leading space , trailing space constraint , change language os take care of making mirror image of english version of views (especially rtl languages). how works is, when change language device setting , when launch app, ios checks selected language , loads storyboard specific language, in case have provide language change feature in app have write code change language on fly.

  • creating separate storyboard- second 1 creating separate storyboards each language , design screens english language first copy , paste same in arabic language storyboard , shift component make mirror image of same.

note:

in both ways providing user change application language in app have take efforts default behaviour of localisation thing need restart app see effect , application language change when change device language, can not change language on fly , see ui change taking place, not happen.

so have in terms of coding part change language in app , user should able see ui in selected language explained below,

which better way?

if app has simple ui , has small scope can go localisation single storyboard multiple languages.

but if app has complex ui , scope of app big suggest go separate storyboard using localisation has limitations or can tricky set constraints complex ui, if got stuck in ui part take more time, not case in using separate storyboard can make changes want.

now lets see code,

below code switching between 2 storyboards,

appdelegate *appdelegate = (appdelegate *)[[uiapplication sharedapplication] delegate];  if ([kgetselectedlanguage isequaltostring:kenglish]) { //load arabic storyboard      [sender setselected:no];      // english language storyboard     uistoryboard *storyboard = [uistoryboard storyboardwithname:@"arabic" bundle:nil];      // create navigation controller rootviewcontroller     uinavigationcontroller *navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:[storyboard instantiateviewcontrollerwithidentifier:@"yourrootviewcontroller"]];      // set windows rootviewcontroller     [appdelegate.window setrootviewcontroller: navigationcontroller];      [[nsuserdefaults standarduserdefaults] setobject:karabic forkey:kselectedlanguage];      [[nsuserdefaults standarduserdefaults] synchronize];  } else { //load english storyboard      [sender setselected:yes];      // english language storyboard     uistoryboard *storyboard = [uistoryboard storyboardwithname:@"english" bundle:nil];      // create navigation controller rootviewcontroller     uinavigationcontroller *navigationcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:[storyboard instantiateviewcontrollerwithidentifier:@"yourrootviewcontroller"]];      // set windows rootviewcontroller     [appdelegate.window setrootviewcontroller: navigationcontroller];      [[nsuserdefaults standarduserdefaults] setobject:kenglish forkey:kselectedlanguage];      [[nsuserdefaults standarduserdefaults] synchronize]; } 

and code re instantiate storyboard in case of localisation (and changing language in app itself),

//change language english appdelegate *delegate = (appdelegate *)[uiapplication sharedapplication].delegate;     [delegate setcountrylanguagecode:@"us" andlanguagecode:@"en"];  //change language arabic appdelegate *delegate = (appdelegate *)[uiapplication sharedapplication].delegate;     [delegate setcountrylanguagecode:@"eg" andlanguagecode:@"ar"];  //re-instantiate storyboard -(void)setcountrylanguagecode:(nsstring *)countrycode andlanguagecode:(nsstring *)languagecode{     [nsbundle setlanguage:languagecode];     uistoryboard *storyref = [uistoryboard storyboardwithname:@"main" bundle:[nsbundle mainbundle]];     self.window.rootviewcontroller = [storyref instantiateinitialviewcontroller]; } 

note:

providing in app language change feature not recommended apple lead confusion between device selected language , application language if requirement , have anyway choice yours.

hope helps you.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -