我如何在 swift 中将 uiview (xib) 显示为警报视图 [英] How can i present uiview (xib) as alert view in swift
本文介绍了我如何在 swift 中将 uiview (xib) 显示为警报视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将我的 xib 显示为警报视图.在 xib 中,主视图将是半透明的,这将防止用户在警报视图启动时点击后台中的任何其他内容.我没有在 xib 中使用视图控制器.
I want to present the my xib as the alert view. In the xib main view is going to be semi-transparent, which will prevent users from tapping on anything else in the background while the alert view is up. I am not using the view controller in xib.
推荐答案
1.获取 XIB 文件对象.
1.Fetch the XIB file object.
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()
这篇关于我如何在 swift 中将 uiview (xib) 显示为警报视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文