0
@objc func rightAnswer(sender : Button) {
        
    if AnsNumber == 0 && sender.tag == 0 {
        
        sender.backgroundColor =  #colorLiteral(red: 0.03577814337, green: 1, blue: 0.0007592695236, alpha: 1)
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
            sender.backgroundColor = #colorLiteral(red: 0.1764705926, green: 0.01176470611, blue: 0.5607843399, alpha: 1)
        }
    }
}

@objc func colorButton1(sender : Button) {
    
    if AnsNumber == 0 && sender.tag == 0 {
        
        sender.backgroundColor =  #colorLiteral(red: 0.03577814337, green: 1, blue: 0.0007592695236, alpha: 1)
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
            sender.backgroundColor = #colorLiteral(red: 0.1764705926, green: 0.01176470611, blue: 0.5607843399, alpha: 1)
        }
    }
    
    else {
        
        rightAnswer(sender: button)
        
        sender.backgroundColor =  #colorLiteral(red: 0.8514541941, green: 0, blue: 0, alpha: 1)
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
            sender.backgroundColor = #colorLiteral(red: 0.1764705926, green: 0.01176470611, blue: 0.5607843399, alpha: 1)
            
        }
    }
}

rightAnswer()方法正在检查用户单击了哪个按钮,并且还检查了用户按下的按钮是否包含正确答案,如果满足条件,颜色将变为绿色,如果不满足条件,它将变为红色。

colorButton1()方法是检查类似的东西,除了有四个按钮,每个按钮都分配了一个标签。这是检查标签等于 0 的按钮。

基本上colorButton1(),当答案错误时,方法会将按钮颜色更改为红色我还需要以绿色显示正确答案的按钮。

4

0 回答 0