【发布时间】:2018-12-20 20:13:50
【问题描述】:
我以模态方式(透明)呈现视图控制器,然后尝试将对话框添加为带有几个按钮的子视图。我希望这个子视图是纯色的,但不透明,但不能让它工作。
我尝试将子视图的 alpha 设置为 1,但它并没有改变外观。
class GameOverViewController: UIViewController {
private let restart = UIButton(type: .custom)
private let mainmenu = UIButton(type: .custom)
override func viewDidLoad() {
//displays view controller modally
super.viewDidLoad()
self.view.backgroundColor = .white
self.view.alpha = 0.6
self.modalPresentationStyle = .overCurrentContext
//add dialogue box
let dialoguebox = UIView(frame: CGRect(origin: CGPoint(x: self.view.frame.width / 2, y: self.view.frame.height / 2), size: CGSize(width: self.view.frame.width / 2, height: self.view.frame.height / 2)))
dialoguebox.backgroundColor = .red
dialoguebox.center = self.view.center
dialoguebox.alpha = 1
self.view.addSubview(dialoguebox)
}
}
【问题讨论】:
标签: ios swift viewcontroller