首页 > 解决方案 > UIAlertAction 按钮不仅仅出现在 iPhone 6s (iOS 14.4)

问题描述

UIAlertController 的标题出现了,但 UIAlertAction 按钮不仅出现在 iPhone 6s 中。请帮我解决这个问题。

以下是我尝试过的代码:

        datePicker.frame = CGRect(x: 0, y: 50, width: 270, height: 230)
        let alertController = UIAlertController(title: dateSelection == DateSelection.FROM_DATE_SELECTION ? "Select date" : "To Date",
                                                message: "\n\n\n\n\n\n\n\n", preferredStyle: .alert)
        
        
        let selectAction = UIAlertAction(title: "Ok", style: .default, handler: { _ in
            self.prepareDates(selectedDate: self.datePicker.date, dateSelection: dateSelection)
        })
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
        
        alertController.view.setNeedsLayout()
        alertController.view.addSubview(datePicker)
        alertController.addAction(selectAction)
        alertController.addAction(cancelAction)
        
        let height: NSLayoutConstraint = NSLayoutConstraint(item: alertController.view!, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: self.view.frame.height * 0.40)
        alertController.view.addConstraint(height);
        present(alertController, animated: true)

标签: iosswiftswift5uialertaction

解决方案


推荐阅读