Swift设置半透明ModalViewContoller

2020-04-29  本文已影响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的子视图下。

上一篇 下一篇

猜你喜欢

热点阅读