0
如何将操作表中UIAlertAction
标题的文本对齐方式更改为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
我怎样才能解决这个问题,所以我可以在动作片更改警报措施文本对齐
非常感谢你
我90%肯定,你需要做一个自定义的警报视图这是因为系统警报观点都有其默认样式的硬连线 –