Как изменить ширину UIAlertController в Swift 4? - PullRequest
0 голосов
/ 10 сентября 2018

Вот один из способов изменить ширину AlertController:

let alertController = UIAlertController(title: "Disconnected", message: "", preferredStyle: .alert)
let width : NSLayoutConstraint = NSLayoutConstraint(item: alertController.view, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 160) 
alertController.view.addConstraint(width)

Но при запуске появится сообщение об ошибке:

    Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x60000009ae50 UIView:0x7f9c4473cbf0.width == 270   (active)>",
    "<NSLayoutConstraint:0x6040002824e0 _UIAlertControllerView:0x7f9c460d4e00'Disconnected'.width >= UIView:0x7f9c4473cbf0.width   (active)>",
    "<NSLayoutConstraint:0x60c00008be00 _UIAlertControllerView:0x7f9c460d4e00'Disconnected'.width == 160   (active)>"

)

Есть ли другой способ изменить AlertControllerширина?Или есть ли способ исправить ошибку?

Любые предложения будут оценены.

...