iOS UIAlertController粗体按钮在8.3中更改

Bbx*_*Bbx 53 button ios uialertcontroller

UIAlertController有两个按钮,样式设置为:

UIAlertActionStyle.Cancel
UIAlertActionStyle.Default
Run Code Online (Sandbox Code Playgroud)

在iOS 8.2中,"取消"按钮为非粗体,"默认"为粗体.在iOS 8.3中,它们已经转换

您可以看到Apple自己的应用程序,例如,设置>邮件>添加帐户> iCloud>输入无效数据,然后在8.3上显示如下:

不支持的Apple ID

了解更多(粗体)确定(非粗体)

而8.2则是另一种方式.

任何解决方法,使它再次像8.2.为什么会改变?

Thi*_*Thi 104

在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) {}
Run Code Online (Sandbox Code Playgroud)

右侧的OK按钮将以粗体显示.

  • 请注意,这仅适用于`UIAlertControllerStyle.Alert`(不适用于操作表)。 (2认同)

Jos*_*ald 15

这是对SDK的有意更改.在这个问题上,我刚收到苹果对此雷达的回应,并说明:

这是一个有意的更改 - 取消按钮将在警报中加粗.

遗憾的是,我在各种变更日志中找不到任何内容.

因此,我们需要在某些地方对我们的应用进行更改,以使某些事情变得有意义.


Ima*_*tit 8

从 iOS 9 开始,UIAlertController有一个名为preferredAction. preferredAction有以下声明:

var preferredAction: UIAlertAction? { get set }
Run Code Online (Sandbox Code Playgroud)

用户从警报中采取的首选操作。[...] 首选操作UIAlertController.Style.alert仅与样式相关;操作表不使用它。当您指定首选操作时,警报控制器会突出显示该操作的文本以强调它。(如果警报还包含取消按钮,则首选操作会收到突出显示而不是取消按钮。) [...] 此属性的默认值为nil


下面示出了如何显示的迅捷5/12的iOS示例代码UIAlertController,将突出一个指定的文本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)
Run Code Online (Sandbox Code Playgroud)