【发布时间】:2018-05-17 00:08:08
【问题描述】:
我有包含单选按钮的自定义 xib。 我正在尝试将此 xib 作为子视图添加到 alertcontroller 中。 但是如您所见,文本正在从 uiview 中输出:
let alert = Bundle.main.loadNibNamed("MyXib", owner: self, options: nil)!.last as! UIView
let alertController = UIAlertController(title: "\n\n\n\n\n\n", message: nil, preferredStyle: .alert)
let margin:CGFloat = 8.0
let rect = CGRect(x: margin, y: margin, width: alertController.view.bounds.size.width - margin * 4, height: 300)
let customViewForAlert = UIView(frame: rect)
customViewForAlert.addSubview(alert)
alertController.view.addSubview(customViewForAlert)
self.present(alertController, animated: true, completion: nil)
我该如何解决? 谢谢
【问题讨论】:
-
如答案中所述 - 你不能。但您可以 做两件事: (1) 将您的 xib 文件用作模态演示视图控制器。 (2) 在弹出窗口中使用它 - 但请注意,在 iPhone 上,您必须添加一些额外的代码才能做到这一点。
-
你可以在一定程度上做到这一点,但你不应该这样做。更多信息请参考此链接developer.apple.com/documentation/uikit/uialertcontroller