I am using MDC (Material design components) to build my UI in an iOS application, I have 2 languages in my app english and arabic, when switching to arabic I am forcing right to left to all my views, it works great as shown in the pictures below:
forcing RTL on all view in AppDelegate as follow:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIView.appearance().semanticContentAttribute = .forceRightToLeft
}
the result is:
But the problem when i push a view controller in left to right mode it looks like this:
But in RTL Mode it look as following:
I am trying to flip the back button horizontally but with no success here is the code in my pushed view controller:
class UserCartViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
(UIApplication.shared.delegate as! AppDelegate).appBar?.navigationBar.backItem?.image?.mdf_imageWithHorizontallyFlippedOrientation()
}
}
the backItem
is nil
in this case but when I delay the code:
class UserCartViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
(UIApplication.shared.delegate as! AppDelegate).appBar?.navigationBar.backItem?.image?.mdf_imageWithHorizontallyFlippedOrientation()
}
}
}
the backItem
has a value and an image but mdf_imageWithHorizontallyFlippedOrientation()
is not working so my questions:
- Is there a better way to fix the default back button of MDCAppBar to be flipped when i force all views to be RTL?
- Why after time delay I get values for the back button is there any function or delegate triggered when the MDCAppBar is ready?
- And finally why
mdf_imageWithHorizontallyFlippedOrientation()
is not working on an image?
Thanks in advance