ios - 如何更改 UIAlertAction 字体或在第二个位置显示 UIAlertActionStyle.cancel 样式 ActionButton?

标签 ios uialertcontroller uialertaction

我不想更改 UILabel.appearance,因为它将适用于所有标签。

如何显示如下图所示的 UIAlertController

需要在第二个位置显示粗体按钮。

默认情况下,当我设置 UIAlertActionStyle.cancel 时,它​​会在第一个位置的确认按钮上显示它。

现在看起来像这样:

我做了一些研究,但没有找到任何解决方案。

最佳答案

Swift 4.2/Swift 5

您需要设置首选操作方法,

//Create alertController
let alert = UIAlertController(title: "title", message: "message", preferredStyle: .alert)

//Create and add the Confirm action
let confirmAction = UIAlertAction(title: "Confirm", style: .default, handler: { (action) -> Void in
    //Do Something here...
})
alert.addAction(confirmAction)

//Create and add the Cancel action
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) -> Void in

    //Do Something here...
})
alert.addAction(cancelAction)

// Set Preferred Action method
alert.preferredAction = confirmAction

self.present(alert, animated: true, completion: nil)

输出将是,

enter image description here

关于ios - 如何更改 UIAlertAction 字体或在第二个位置显示 UIAlertActionStyle.cancel 样式 ActionButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48555399/

相关文章:

ios - 返回表中的单元格数会产生 NSInternalInconsistenceyException

iPhone 3.2模拟器

ios - 使用 .long 或 .full 的日期格式不会导致小时/分钟/天/秒

ios - 如何使 uitextfield 只接受数字和逗号

ios - 我的警报 Controller 操作究竟如何将文本 append 到标签?

ios - 如何在 ObjC 中普遍更改 UIAlertController 按钮颜色

ios - UIDatePicker View - 在 iOS 7 中看起来与 iOS 6 相同

ios - 如何使用 iOS8 在 UIAlertController 中设置 UITableView 的位置和大小

ios - 为什么 UIView 的 CALayer.speed 为零会阻止 UIAlertController 的按钮工作?

ios - 从 UIAlertAction 处理程序更新 UILabel 在 Swift 4 中不起作用