Я UIAlertViewController
, который я использую для показа тоста. Я установил выравнивание по центру, и все работает нормально. Если я переключаю язык с английского на арабский или наоборот, сообщение всегда выравнивается по естественному левому краю.
func displayToast(vc: UIViewController, message: String, seconds: Double = 2.0, completion: (() -> Void)? = nil) {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.center
let messageText = NSMutableAttributedString(
string: message,
attributes: [
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body),
NSAttributedString.Key.foregroundColor: UIColor.gray
]
)
alert.setValue(messageText, forKey: "attributedMessage")
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + seconds, execute: {
alert.dismiss(animated: true, completion: nil)
})
alert.modalPresentationStyle = .popover
if let popoverPresentationController = alert.popoverPresentationController {
popoverPresentationController.sourceView = vc.view
popoverPresentationController.sourceRect = vc.view.bounds
popoverPresentationController.permittedArrowDirections = []
}
vc.present(alert, animated: true, completion: completion)
}
Как сделать так, чтобы на коммутаторе RTL выровнялось сообщение с предупреждением?