如何向UIAlertAction添加详细信息标签



我正在学习iOS,有一个问题。我应该如何向UIAlertAction添加详细信息标签?类似于带有UITableViewCellStyleSubtitle的UITableViewCell。

谢谢。

let attributedString = NSAttributedString(string: "My Message",
attributes: [NSAttributedStringKey.font : UIFont(name: "Avenir-Light", size: 20)!])
let alert = UIAlertController(title: "Title", message: "", preferredStyle: .alert)
alert.setValue(attributedString, forKey: "attributedMessage")
let cancelAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(cancelAction)
present(alert, animated: true, completion: nil)

试试这个。。

不能在UIAlertAction中添加detailedText(两个标签(。但是,您可以制作自己的自定义警报视图和操作按钮。如果你没有时间,你可以搜索第三方图书馆。

此外,如果UIAlertAction能够设置属性文本,您可以将文本的两行附加为UIAlertAction标题(通过在NSAttributedString中用小字体添加"\n"以显示详细标签(。但遗憾的是,并没有公共的API可以将属性化的String设置为UIAlertAction标题。但是有一个私人的API,正如在这个回答中提到的UIAlertController自定义字体,大小,颜色

最新更新