当我再次按下播放按钮时,它不起作用。我刚刚有这个代码涉及播放再次按钮。我应该在这里添加什么?如何向playAgain
按钮添加功能?这是我的代码:
let playAgain: UIButton = UIButton(frame: CGRectMake(-10, 400, 400, 150))
playAgain.setTitle("Play Again", forState: UIControlState.Normal)
playAgain.titleLabel!.font = UIFont(name: "Helvetica", size: 50)
playAgain.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
playAgain.tag = 1
self.view!.addSubview(playAgain)
答案 0 :(得分:1)
使用您喜欢的任何名称实现一个函数,如下所示:
func buttonPressed(sender: UIButton) {
// do something
}
然后将此功能设置为按钮的操作:
playAgain.addTarget(self, action: "buttonPressed:", forControlEvents: .TouchUpInside)