Ich möchte eine Unteransicht zu meinem Alarmcontroller hinzufügen. Aber warum gehen die Knöpfe oben? Wie behebe ich das Problem?UIAlertController: addSubview
let alert = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.alert)
let somethingAction = UIAlertAction(title: "Something", style: .default, handler: {(alert: UIAlertAction!) in print("something")})
let cancelAction = UIAlertAction(title: "Annuler", style: .cancel, handler: {(alert: UIAlertAction!) in print("cancel")})
alert.addAction(somethingAction)
alert.addAction(cancelAction)
let customView = UIView()
customView.backgroundColor = .green
customView.translatesAutoresizingMaskIntoConstraints = false
customView.widthAnchor.constraint(equalToConstant: 128).isActive = true
customView.heightAnchor.constraint(equalToConstant: 128).isActive = true
alert.view.addSubview(customView)
customView.centerXAnchor.constraint(equalTo: alert.view.centerXAnchor).isActive = true
customView.topAnchor.constraint(equalTo: alert.view.topAnchor).isActive = true
customView.bottomAnchor.constraint(equalTo: alert.view.bottomAnchor, constant: -32).isActive = true
self.present(alert, animated: true, completion:{})
'UIAlertController' ist nicht entworfen, um das Hinzufügen von Unteransichten zu unterstützen. Wenn Sie eine benutzerdefinierte Warnung verwenden möchten, verwenden Sie eine benutzerdefinierte Warnung, nicht "UIAlertController". – rmaddy
Probieren Sie http://stackoverflow.com/a/32790860/7250862 –
@RajeshkumarR Danke, aber er verwendet eine Menge "/ n". Aber meine Sichthöhe ist dynamisch, also ist es keine gute Lösung für mich. – Louis