以前所有的对话框和textField都运行良好.但不是我不知道这些TextFields如何突然变为单行三联.(就像这里的一些消息......)
let alert = UIAlertController(title: "Cancel Booking !!", message: "Are you sure you want to cancel your booking?", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "No", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: self.cancelMessageDialog))
self.present(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我试图更改标题fontSize中的UIAlertController,但我不能管理如何我设置NSMutableAttributedString的title-属性。
所以我一直在NSMutableAttributedString使用以下代码创建:
let title = NSMutableAttributedString(string: user.fullName)
let range = NSRange(location: 0, length: title.length)
title.addAttribute(NSAttributedStringKey.font, value: UIFont.TextStyle.largeTitle, range: range)
Run Code Online (Sandbox Code Playgroud)
现在对我来说棘手的部分是如何弄清楚如何将新标题设置为UIAlertController,因为它需要一个String?值。
我环顾四周,发现UILabel在呈现UIAlertController. 但是如何使用我自己的自定义覆盖title-property ?UIAlertControllerUILabel
present(myUIAlertController, animated: true) {
// Creating the UILabel depending on string length
// Set the NSMutableAttributedString value to the custom UILabel and override title property.
}
Run Code Online (Sandbox Code Playgroud)
或者也许有更简单的方法来解决这个问题?
nsmutableattributedstring swift uialertviewcontroller swift4