如何在swift中的UIAlertAction中将文本对齐方式更改为左侧

如何在swift中的UIAlertAction中将文本对齐方式更改为左侧,swift,uialertcontroller,Swift,Uialertcontroller,如何用swift语言将行动表中的UIAlertAction标题的文本对齐方式更改为左侧 下面是我的代码: let alertController = UIAlertController() let alertImage = UIAlertAction(title: "Image", style: .default, handler: nil) let alertVideo = UIAlertAction(title: "Video", style: .defaul

如何用swift语言将行动表中的
UIAlertAction
标题的文本对齐方式更改为左侧

下面是我的代码:

let alertController = UIAlertController()
        let alertImage = UIAlertAction(title: "Image", style: .default, handler: nil)
        let alertVideo = UIAlertAction(title: "Video", style: .default, handler: nil)

        let alertFile = UIAlertAction(title: "File", style: .default, handler: nil)
        let alertCancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)

        let paragraphStyle = NSMutableParagraphStyle()
        // Here is the key thing!
        paragraphStyle.alignment = .left

        let messageText = NSMutableAttributedString(
            string: "Video",
            attributes: [
                NSParagraphStyleAttributeName: paragraphStyle,
                NSFontAttributeName : UIFont.preferredFont(forTextStyle: .subheadline),
                NSForegroundColorAttributeName : UIColor.black
            ]
        )

        // add icon to the left alert action
        let image = UIImage(named: "video")
        alertVideo.setValue(image, forKey: "image")
        // align text in the alertAction
        alertVideo.setValue(UIColor.black, forKey: "titleTextColor")
        alertVideo.setValue(messageText, forKey: "attributedTitle")

        alertController.addAction(alertImage)
        alertController.addAction(alertVideo)
        alertController.addAction(alertFile)
        alertController.addAction(alertCancel)

        present(alertController, animated: true, completion: nil)
我得到的错误消息是

[<UIAlertAction 0x7a6eb760> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key attributedTitle
[setValue:forUndefinedKey:]:此类不符合key attributedTitle的键值编码
如何解决此问题,以便在“操作”表中更改警报操作的文本对齐方式


非常感谢

我认为您不能使用默认的UIAlertController来实现这一点

但您可以尝试使用自定义框架,如OKAlertController

它扩展了定制功能


我认为使用默认UIAlertController无法实现这一点

但您可以尝试使用自定义框架,如OKAlertController

它扩展了定制功能


我90%确定您需要为此执行自定义警报视图,因为系统警报视图具有默认的硬接线样式。我90%确定您需要为此执行自定义警报视图,因为系统警报视图具有默认的硬接线样式