我正在尝试在名为containerView的UIView中添加UIButton。 containerView正常显示,但UIButton根本没有显示。这是我的代码:
let containerView = UIView()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.containerView.frame = CGRect(x: self.view.frame.size.width - 100, y: 200, width: 225, height: 70)
self.containerView.backgroundColor = UIColor.gray
self.containerView.layer.cornerRadius = 20
self.containerView.clipsToBounds = true
self.view.addSubview(self.containerView)
let button1: UIButton = UIButton()
button1.frame = CGRect(x: self.view.frame.size.width - 70, y: 200, width: 35, height: 35)
button1.clipsToBounds = true
button1.setTitle("Tesing Button", for: .normal)
self.containerView.addSubview(button1)
}
有任何帮助吗?谢谢!
答案 0 :(得分:1)
您的按钮框架位置不正确。您已将y
的值设置为200,这超出了容器视图的大小。