gpt4 book ai didi

ios - 在 iOS8 Swift 中左对齐 AlertView 消息

转载 作者:搜寻专家 更新时间:2023-10-31 08:33:57 27 4
gpt4 key购买 nike

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

但问题是(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()

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

最佳答案

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

 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)

关于ios - 在 iOS8 Swift 中左对齐 AlertView 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30481853/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com