我在快速游乐场里有这个名为“开始按钮”的UIButton。这是它的设置。
func setupStartButton(){ startButton.frame = CGRect(x:15,y:550,width:125,height:50) …
我看不到你的其余代码。我刚刚创建了一个,以便您可以与自己的代码进行比较。
import UIKit import PlaygroundSupport class VC: UIViewController { let startButton = UIButton(type: .system) override func viewDidLoad() { super.viewDidLoad() setupStartButton() } func setupStartButton() { startButton.frame = CGRect(x: 15, y: 550, width: 125, height: 50) startButton.backgroundColor = UIColor(ciColor: CIColor(red: 255/255, green: 0/255, blue: 77/255, alpha: 1.0)) startButton.layer.cornerRadius = 20 startButton.setTitle("Start", for: .normal) startButton.setTitleColor(.white, for: .normal) startButton.addTarget(self, action: #selector(startButtonTapped), for: .touchUpInside) view.addSubview(startButton) } @objc func startButtonTapped() { print("Hello") } } let vc = VC() PlaygroundPage.current.liveView = vc