在 Swift 中更改我的 @IBAction 按钮的外观

Changing the appearance of my @IBAction button in Swift out of its func

我正在编写一个应用程序,其中有一个滚动视图,我想要的是首先将按钮的 alpha 设置为 0,然后在用户滚动到最后一页时将其更改为 1。我正在写这样的代码:

@IBAction func startButton(sender: UIButton) {
        sender.layer.cornerRadius = 2.0
        sender.alpha = 0.0
 }

extension UserGuideViewController: UIScrollViewDelegate {
    func scrollViewDidScroll(scrollView: UIScrollView) {
        let offset = scrollView.contentOffset
        pageControl.currentPage = Int(offset.x / view.bounds.width)
        if pageControl.currentPage == numberOfPages - 1 {
            UIView.animateWithDuration(0.5) {
                self.startButton.alpha = 1.0
            }
        } else {
            UIView.animateWithDuration(0.2) {
                self.startButton.alpha = 0.0
            }
        }
    }
}

上面写着 Value of type (UIButton)->() has no member alpha。我不知道该怎么做。 我知道如果这个按钮是 @IBOutlet 会很容易,但我需要将它设置为 @IBAction 以便当它被触摸时我可以显示另一个视图控制器。

您需要为按钮创建@IBOutlet@IBAction。从 Interface Builder 拖动两次到您的视图控制器,然后从弹出菜单中 select 适当的值(outlet 或 action)并给它们不同的名称。然后在您的 scrollViewDidScroll 方法中访问插座。