0
我正在練習/快速學習,並且正在製作一個tic tac toe遊戲。我試圖讓按鈕圖像改變,但點擊按鈕時沒有改變。按鈕圖像不會改變
我是否正確地將此操作應用於發件人的點擊事件處理程序中?如果是這樣,爲什麼這可能不起作用?
感謝
class ViewController: UIViewController {
var playerOneTurn = true;
let cross = UIImage(named: "Cross") as UIImage;
let naught = UIImage(named: "naught") as UIImage;
@IBAction func topLeftBtn(sender: UIButton) {
var image = sender.imageForState(UIControlState.Normal);
if(image == nil){
if(playerOneTurn == true){
sender.setImage(naught,forState: UIControlState.Highlighted);
playerOneTurn = false;
}else{
sender.setImage(cross,forState: UIControlState.Highlighted);
playerOneTurn = true;
}
}
checkForWinner();
}
您是否整理出來了?請考慮接受/ upvoting有助於你的答案。非常感謝。 – 2014-09-26 23:08:24