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

时间:2018-02-01 04:34:19

标签: ios uialertcontroller uialertaction

我不想更改abstract class Model { protected $PDO; protected $PDOgen; public function _construct(){ $this->PDOgen = new \Namespace\PDOgen(); //edited2 line; } } class SomeModel extends Model{ public function _construct(){ $this->PDO = $this->PDOgen->getPDOName('db_name_for_this_model'); //edited2 line; } public function fun(){ $this->PDOgen-> ... $this->PDO-> ... } } class PDOgen { ... public function getPDOName($db_name) { return getPDO( ... ); } } 因为它适用于所有标签。

如何显示UILabel.appearance,如下图所示?

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

Need to show Bold Button in the Second Position

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

现在看起来像这样:

It looks like this now

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

3 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:0)

当然,你可以。试试这个

let alertView = UIAlertController(
    title: "Home",
    message: "Are you sure for delete Reminder",
    preferredStyle: .alert)
alertView.view.tintColor = .green
let confirmAction = UIAlertAction(title: "Confirm", style: .cancel) { (_) in
     // Do confirm
}
alertView.addAction(confirmAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .default) { (_) in
    // Do cancel
}
alertView.addAction(cancelAction)
self.present(alertView, animated: true, completion: nil)

答案 2 :(得分:0)

您需要以正确的顺序将它们添加到 alertView 中!如果您想更改订单,只需添加第二个确认按钮!

alert.addAction(cancelAction)
alert.addAction(confirmAction)

代替:

alert.addAction(confirmAction)
alert.addAction(cancelAction)