0
アクションシートのUIAlertAction
タイトルのテキストアライメントを迅速に左側に変更するにはどうすればよいですか?以下 即時のUIAlertActionで左にテキストの配置を変更する方法
[<UIAlertAction 0x7a6eb760> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key attributedTitle
あり得る
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)
ありがとうございました
を拡張しました –