Reputation: 5081
I am trying to do update all my controllers after change English language to urdu (RTL) language.
Means,
If tableview cell contains image present in left side and text present at Right side in tableview cell. When user select urdu language it goes swap. Image added in Right side and text goes to left side.
Used Auto layout for this. Setting proper constraint Like leading and trailing for It will take care for that if we change the apple language.
Used this code to set the Apple language. Written one notification for refresh the views. But it will not work immediately.
If user select urdu language
if([preferredLangCode isEqualToString:@"ur"])
{
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"ur", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter]postNotificationName:@"AppLayoutDirectionTrigger" object:nil];
}
For Refresh view
-(void)updateUIForRTLSupportConfirmedScreen:(NSNotification *)notification
{
for (UIView *view in self.view.subviews)
{
[view setNeedsDisplay];
}
}
Not update my view not swap the view subviews.
It will work if i stop the app and run again it works. But I want immediate reflect the changes.
Upvotes: 0
Views: 371
Reputation:
The recommended approach is to use the system language, and remove the language selection from your app. Starting from iOS 8, users can select Urdu from the language list, even if it is not supported on iOS system apps. Like this, you don't have to worry about implementing a language chooser and changing AppleLanguages
.
Keeping your language chooser is a difficult task to do. On iOS 8, you will have to remove all of the constraints of all of your views, and re-create them to use the opposite Left and Right attributes for each. On iOS 9, you will have to go through every single one of your views and update the semanticContentAttribute
of each view you want to display.
Upvotes: 1