美文网首页
Swift设置半透明ModalViewContoller

Swift设置半透明ModalViewContoller

作者: 冲云简 | 来源:发表于2020-04-29 18:12 被阅读0次

ios 8.0 以前

let vc = UIViewController()
vc.backgroundColor = UIColor(hexString: "#dedede", alpha: 0.5)
vc.modalPresentationStyle = .overCurrentContext
UIApplication.shared.keyWindow?.rootViewController.present(vc, animated: false, completion: nil)

ios8.0以后

let vc = UIViewController()
vc.backgroundColor = UIColor(hexString: "#dedede", alpha: 0.5)
vc.modalPresentationStyle = UIModalPresentationStyle(rawValue: UIModalPresentationStyle.overCurrentContext.rawValue |
                UIModalPresentationStyle.fullScreen.rawValue)!
present(vc, animated: false, completion: nil)

注: 如果你添加一个UIControl的视图,请记得放在一个UIView的子视图下。

相关文章

网友评论

      本文标题:Swift设置半透明ModalViewContoller

      本文链接:https://www.haomeiwen.com/subject/prmnwhtx.html