我已经创建了一个警报视图,并希望将警报视图的文本对齐到左边并使用此代码,但是这个(alert.subviews).count
是零。 ![在此处输入图像说明] [1]
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()
我想将消息对齐到左边但是警报的子视图计数为零
提前致谢
警告文字“条款和条件”保持对齐
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)
我发现这个要点创建了一个左对齐文本的警报。对要点的作者 - 非常感谢你:https://gist.github.com/nvkiet/29e4d5b5bef0865ee159
基本上,在创建UIAlertController时:
•提供title
•Cajaxasopi =蓝色
•按以下方式创建NSMutableAttributedString:
message
•将属性字符串添加为alertcontroller上的键:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.left
let attributedMessage: NSMutableAttributedString = NSMutableAttributedString(
string: message, // your string message here
attributes: [
NSParagraphStyleAttributeName: paragraphStyle,
NSFontAttributeName: UIFont.systemFont(ofSize: 13.0)
]
)
•出示警报
UIAlertView不支持textAlignment
你必须看到自定义解决方案。
let alert = UIAlertController(title: title, message: nil, preferredStyle: UIAlertControllerStyle.alert)
alert.setValue(attributedMessage, forKey: "attributedMessage")
根据qazxsw poi,您无法自定义qazxsw poi的外观,请在给定链接中查看警报视图的外观部分。
我有两种解决方法
只需创建此功能,并在任何需要的地方调用它
https://github.com/wimagguc/ios-custom-alertview