In my app there is three languages i.e. ar , fr & en. And Based on the app language is changing the app language and semantics.
In my app, app language is properly changed as per the requirement but its semantics is not changing.
Here is the tried code what I am doing when user changed the language.
let cur_lang = Localize.currentLanguage()
print("current lang; \(cur_lang)")
if cur_lang == "ar"{
UIView.appearance().semanticContentAttribute = .forceRightToLeft
}
else{
UIView.appearance().semanticContentAttribute = .forceLeftToRight
}
imgView.image = UIImage(named: "flag".localized())
lblTitle.text = "Title".localized()
lblDescription.text = "Description".localized()
lblName.text = "Name".localized()
tfName.text = "textName".localized()
Here is the gif of the screen.
Required Output:
Edit
If I take all contents in a view , then it is working as expected but natural text alignment and navigation bar is still uneffected.
It is not possible to flip each and every view as it may reduce app performance if there is complex layout.
So I tried self.view.semanticContentAttribute = .forceRightToLeft
and it does not make any difference.
My every UI component have leading trailing not left right and respect language direction is also selected.
UIAppearance
doc: "iOS applies appearance changes when a view enters a window, it doesn’t change the appearance of a view that’s already in a window. To change the appearance of a view that’s currently in a window, remove the view from the view hierarchy and then put it back." – ChloromycetinUIView.appearance().semanticContentAttribute = ...
to work. – ChloromycetinUIView.appearance().semanticContentAttribute
, if you see my code above. It does not make any change in UI. And i din't fount any other way to do this. Now either I have to usepseudo language
(it does not make any sense in real - app) or change each and every UI with loop (it reduces app performance). – Perdure