如何使用快速语言将“操作”表单中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
如何解决此问题,以便更改操作表中的“警报措施”
的文本对齐方式非常感谢
答案 0 :(得分:0)
我认为您无法使用默认的UIAlertController进行此操作。
但您可以尝试使用自定义框架,例如OKAlertController。
它扩展了自定义