我们可以在swift中更改UIAlertController按钮的高度和宽度

时间:2017-05-20 09:00:52

标签: ios swift swift3 ios10 uialertcontroller

我想在swift中自定义UIAlertviewcontroller的控件,并在swift中更改Cancel和OK按钮的宽度和高度。 有没有办法实现这个目标?Just similar to this

1 个答案:

答案 0 :(得分:-1)

请尝试以下代码: -

//// 更改警报视图控制器的高度

*

let alertController = UIAlertController(title: nil, message: "hello", preferredStyle: .Alert)
    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
        // hide action sheet
    }
    alertController.addAction(cancelAction)
    var height:NSLayoutConstraint = NSLayoutConstraint(item: alertController.view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: self.view.frame.height * 0.80)
    alertController.view.addConstraint(height);
    self.presentViewController(alertController, animated: true, completion: nil)

*