If this helps anyone, the accepted answer will change the height of UIAlertController, but not the width. So the better way to change both height and width of UIAlertController is change constraints on one of the subviews of UIAlertController rather than its view directly.
override func updateViewConstraints()
{
let widthConstraint:NSLayoutConstraint = NSLayoutConstraint(item: self.view.subviews[0], attribute:
NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 120.0)
let heightConstraint:NSLayoutConstraint = NSLayoutConstraint(item: self.view.subviews[0], attribute:
NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute:
NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 120.0)
for constraint in self.view.subviews[0].constraints {
if constraint.firstAttribute == NSLayoutAttribute.width && constraint.constant == 270{
NSLayoutConstraint.deactivate([constraint])
break
}
}
self.view.subviews[0].addConstraint(widthConstraint)
self.view.subviews[0].addConstraint(heightConstraint)
super.updateViewConstraints()
}
*NOTE: Do not forget to deactivate default width constraint, to avoid conflicting constraints.
Default height constraint won't cause conflict with added height constraint. But you can remove default height constraint as well for coherent code.
UIAlertView
, this is the new iOS 8UIAlertController
. – Cambyses