2016-09-20 105 views
1

我想将我的xib显示为警报视图。 在xib主视图中将是半透明的,这将阻止用户在警报视图启动时在背景中的任何其他位置点击。我没有在xib中使用视图控制器。如何在swift中将uiview(xib)作为警报视图显示

+0

这应该是一个简单的搜索,试试这个http://stackoverflow.com/questions/31997885/how-to-create-custom-uialertcontroller-in-swift-ios –

回答

5

// 1.声明视图像这样的showAlert方法里面

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() 
+0

我没有使用的UIViewController 。我制作了xib,它是uiview的子类。我已经在xib中创建了我的设计,并且我想将它作为uialert视图展示。 –

+0

我编辑了我的答案。请检查。 – Vishnuvardhan

+0

非常感谢你Vishnuvardhan.Its nice –

相关问题