在 iOS8 Swift 中对齐 Left AlertView 消息

Fat*_*han 6 uialertview ios swift

我创建了一个警报视图,我想将警报视图的文本向左对齐并使用此代码。

但问题是它(alert.subviews).count0

这是我的代码:

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()
Run Code Online (Sandbox Code Playgroud)

我想将消息左对齐,但警报的子视图计数为 0

iOS*_*eek 5

警告文本“条款和条件”左对齐

 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)
Run Code Online (Sandbox Code Playgroud)


Sho*_*aib 0

UIAlertView不支持textAlignment

您必须查看自定义解决方案。

https://github.com/wimagguc/ios-custom-alertview