【问题标题】:How can i present uiview (xib) as alert view in swift如何在 swift 中将 uiview (xib) 呈现为警报视图
【发布时间】:2017-01-27 22:32:33
【问题描述】:

我想将我的 xib 显示为警报视图。 在 xib 中,主视图将是半透明的,这将防止用户在警报视图启动时点击背景中的任何其他内容。我没有在 xib 中使用视图控制器。

【问题讨论】:

标签: ios swift storyboard


【解决方案1】:

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

【讨论】:

  • 我没有使用 uiviewcontroller。我已经制作了 xib,它是 uiview 的子类。我已经在 xib 中创建了我的设计,我想将它呈现为 uialert 视图。我可以吗???
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-12
  • 2018-02-13
  • 1970-01-01
  • 2021-01-06
  • 2018-05-09
相关资源
最近更新 更多