【发布时间】:2017-08-02 04:59:08
【问题描述】:
我正在 swift 3 中构建一个测验应用程序,它利用 UITableViewController 列出问题,我想使用一个警报视图来发布问题,并提供多种答案供您选择。我让它按照我想要的方式工作,有一个巨大的怪癖,那就是长答案的字体要小得多,并通过用省略号替换答案中间的文本来截断。
如何在 AlertView 操作中获得自动换行的答案,并保持相同大小的字体?请注意,在一定字符长度之后在答案中手动插入“\n”是不现实的,因为问题字典中有数百个问题。
这是 AlertView 的代码:
func showQuestion(questionNum: Int) {
let alertTitle = "Question \(questionNum + 1)"
let qDict = test[questionNum] as! [String:String]
let alertMessage = qDict["Question"]
// create the alert
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
// add the actions (buttons)
if qDict["Option-A"] != "" {
alert.addAction(UIAlertAction(title: qDict["Option-A"], style: UIAlertActionStyle.default, handler: nil))
}
if qDict["Option-B"] != "" {
alert.addAction(UIAlertAction(title: qDict["Option-B"], style: UIAlertActionStyle.default, handler: nil))
}
if qDict["Option-C"] != "" {
alert.addAction(UIAlertAction(title: qDict["Option-C"], style: UIAlertActionStyle.default, handler: nil))
}
if qDict["Option-D"] != "" {
alert.addAction(UIAlertAction(title: qDict["Option-D"], style: UIAlertActionStyle.default, handler: nil))
}
if qDict["Option-E"] != "" {
alert.addAction(UIAlertAction(title: qDict["Option-E"], style: UIAlertActionStyle.default, handler: nil))
}
alert.addAction(UIAlertAction(title: "Come back to this one", style: UIAlertActionStyle.destructive, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
}
【问题讨论】:
-
显示你尝试过的代码
-
我在图片下方添加了代码。感谢您的关注!
标签: ios swift3 uialertcontroller