除了我的其他答案之外,您还可以通过编程方式添加一个按钮。
声明:
let button = UIButton()
如果需要,创建一个名为 setupView() 的函数
private func setupView() {
//Here we set up the size and attributes of the button.
currencyButton.frame = CGRect(x: self.view.frame.size.width - 60, y: 60, width: 50, height: 50)
currencyButton.backgroundColor = UIColor.red
currencyButton.setTitle("YourButtonTitle", for: .normal)
currencyButton.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
self.view.addSubview(currencyButton)
}
并使用按钮:
@objc func buttonAction(sender: UIButton!) {
//Do whatever.
print("ButtonTapped")
}
最后,确保在 viewDidLoad() 中调用了 setupView():
override func viewDidLoad() {
super.viewDidLoad()
setupView()
self.delegate = self
configurePageControl()
self.dataSource = self
}
当您滚动浏览页面视图时,此按钮将留在屏幕上。
如果这回答了您的问题,请告诉我。