具有两个样式设置的按钮的UIAlertController:
UIAlertActionStyle.Cancel
UIAlertActionStyle.Default在iOS 8.2中,取消按钮是非粗体的,默认是粗体的。在iOS 8.3中,他们进行了转换
您可以看到苹果自己的应用程序,例如,设置>邮件>添加帐户> iCloud >输入无效数据,然后在8.3上显示如下:
不支持Apple ID
学习更多(粗体) OK (非粗体)
而8.2的情况正好相反。
任何解决办法,使它成为8.2再次。为什么它变了?
发布于 2016-05-02 11:53:18
在iOS 9中,可以将preferredAction值设置为希望按钮标题为粗体的操作。
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
let OKAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alert.addAction(cancelAction)
alert.addAction(OKAction)
alert.preferredAction = OKAction
presentViewController(alert, animated: true) {}右边的OK按钮将是粗体字体。
发布于 2015-05-06 05:54:54
这是对SDK的有意更改。我刚刚收到苹果公司对this radar的回应,他说:
这是一种有意的更改--取消按钮将被加粗显示为警报。
不幸的是,我在各种更改日志中找不到提到这一点的任何东西。
因此,我们需要在一些地方对我们的应用程序进行修改,使一些事情变得有意义。
发布于 2019-03-13 21:14:10
从iOS 9开始,UIAlertController就有一个名为preferredAction的属性。preferredAction有以下声明:
var preferredAction: UIAlertAction? { get set }用户从警报中采取的首选操作。..。首选操作仅与
UIAlertController.Style.alert样式相关;操作表不使用该操作。指定首选操作时,警报控制器将突出显示该操作的文本,以强调该操作。(如果警报还包含“取消”按钮,则首选操作将接收高亮显示而不是“取消”按钮。)此属性的默认值为nil。
下面的Swift 5/ iOS 12示例代码展示了如何显示将使用preferredAction突出显示指定UIAlertAction文本的preferredAction
let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let okAction = UIAlertAction(title: "OK", style: .default, handler: { action in
print("Hello")
})
alertController.addAction(cancelAction)
alertController.addAction(okAction)
alertController.preferredAction = okAction
present(alertController, animated: true, completion: nil)https://stackoverflow.com/questions/29590534
复制相似问题