0

当语言为阿拉伯语时,我在 IOS 10 中遇到 UIAlertAction 文本对齐问题。

有时操作表以这种方式显示: 在此处输入图像描述

有时它以这种方式显示: 在此处输入图像描述

这个问题只是在 IOS 10 上,我怎么能总是设置 textAlignmetCenter ?

谢谢

4

1 回答 1

0

我已成功使用以下方法来对齐和设置 UIAlertControllers 文本的样式:

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Center

let messageText = NSMutableAttributedString(
    string: "The message you want to display",
    attributes: [
        NSParagraphStyleAttributeName: paragraphStyle,
        NSFontAttributeName : UIFont.preferredFontForTextStyle(UIFontTextStyleBody),
        NSForegroundColorAttributeName : UIColor.blackColor()
    ]
)

myAlert.setValue(messageText, forKey: "attributedMessage")

如果您使用"attributedTitle", 而不是"attributedMessage"

于 2016-11-21T20:21:35.953 回答