我是swift编码的新手,当我试图通过代码添加按钮时,它不会显示在模拟器中。按钮未显示swift
我将main.storyboard中视图的尺寸更改为375 * 1114 有滚动视图和内部视图,并且具有相同的尺寸。 也有5个集合视图。 这些都是由故事板设置的。
的代码我使用:
let fullScreenSize = UIScreen.main.bounds.size
let plusButton = UIButton(type: .custom)
plusButton.frame = CGRect(x: 300, y: 600, width: 50, height: 50)
plusButton.layer.cornerRadius = 0.5 * plusButton.bounds.size.width
plusButton.clipsToBounds = true
plusButton.setImage(UIImage(named: "plus.png"), for: .normal)
plusButton.center = CGPoint(x: fullScreenSize.width * 0.9, y: fullScreenSize.height * 0.9)
plusButton.addTarget(self, action: #selector(plusButtonPressed), for: .touchUpInside)
self.view.addSubview(plusButton)
我试图让按钮留在模拟器的右下角所有的时间。我怎样才能做到这一点?谢谢。
添加按钮作为ScrollView视图的子视图! –
尝试'self.view.bringSubview(toFront:plusButton)' –
在调试器中运行应用程序,然后点击“查看调试器”按钮(参见WWDC 2016 [可视化调试与Xcode](https://developer.apple .com/videos/play/wwdc2016/410 /)约5分钟)。然后你可以找出它的位置,从那里你应该能够轻松地调试问题。 – Rob