Ios – Align Left AlertView Message in iOS8 Swift

iosswiftuialertview

I have created an alert view and I want to align the text of the alert view to left and use this code.

But the problem is that (alert.subviews).count is 0.

Here is my code:

let alert = UIAlertView(title: "Details:", message: "Composer: abcdfg \nShow:sdfa\nPerformer:asdasdf\nLanguage:farsi\nFirst Line:asdfasdfagadf", delegate: nil, cancelButtonTitle: "OK")
                   
for view in alert.subviews{
  if view.isKindOfClass(UILabel){
    (view as UILabel).textAlignment = NSTextAlignment.Left
   }
}
println((alert.subviews).count)
alert.show()

I want to align the message to left but the subviews count for alert is 0

Best Solution

Text of alert "Terms and condition" is left Aligned

 let alertController = UIAlertController(title: "iosGeek", message: "Terms and Condition", preferredStyle: .alert)
    let OKAction = UIAlertAction(title: "OK", style: .cancel) { (action) in
        alertController.dismiss(animated: true, completion: nil)
    }
    alertController.addAction(OKAction)

    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.alignment = NSTextAlignment.left

    let messageText = NSMutableAttributedString(
        string: "Terms and Condition",
        attributes: [
            NSParagraphStyleAttributeName: paragraphStyle,
            NSFontAttributeName: UIFont.systemFont(ofSize: 13.0)
        ]
    )

    alertController.setValue(messageText, forKey: "attributedMessage")
    self.present(alertController, animated: true, completion: nil)