2017-08-13 7 views
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) 

ありがとうございました

+1

を拡張しました –

答えて

0

私はあなたがdefa UIAlertControllerです。

しかし、OKAlertControllerのようなカスタムフレームワークを使用しようとすることができます。

それは私がシステムアラートビューは、デフォルトは、ハードワイヤードスタイリング持っているので、あなたは、このためのカスタムアラートビューを行う必要があると思い、90%確信してカスタマイズ

https://github.com/OlehKulykov/OKAlertController

関連する問題