我有一个包含 3 个页面的页面 View Controller 。我想要一个“ float ”按钮在所有按钮之上可见。我试过为 PageView 使用容器 View ,但这似乎不起作用。我还能如何让按钮在所有 3 个页面上保持可见?
我试过使用这个问题中所述的容器 View : UIButton across all pages of UIPageViewController
最佳答案
除了我的其他答案,您还可以通过编程方式添加按钮。
声明:
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
}
当您滚动浏览页面 View 时,此按钮将保留在屏幕上。 让我知道这是否回答了您的问题。
关于ios - 如何在 UIPageViewController 上添加按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52191014/