【发布时间】:2017-01-27 22:32:33
【问题描述】:
我想将我的 xib 显示为警报视图。 在 xib 中,主视图将是半透明的,这将防止用户在警报视图启动时点击背景中的任何其他内容。我没有在 xib 中使用视图控制器。
【问题讨论】:
-
这应该很容易搜索,试试这个stackoverflow.com/questions/31997885/…
标签: ios swift storyboard
我想将我的 xib 显示为警报视图。 在 xib 中,主视图将是半透明的,这将防止用户在警报视图启动时点击背景中的任何其他内容。我没有在 xib 中使用视图控制器。
【问题讨论】:
标签: ios swift storyboard
1.获取XIB文件对象。
let alert = NSBundle.mainBundle().loadNibNamed("Alert", owner: self, options: nil).last as! UIView
2.编写便捷方法。
static func showAlert() {
let windows = UIApplication.sharedApplication().windows
let lastWindow = windows.last
alert.frame = UIScreen.mainScreen().bounds
lastWindow?.addSubview(alert)
}
static func removeAlert() {
alert.removeFromSuperview()
}
3.调用方法。
//showing alert
ClassName.showAlert()
//remove alert
ClassName.removeAlert()
【讨论】: