我想创建一个带有x和o的tic tac toe样式板。第一部分工作并成功更改按钮代码。
func buttonAction(sender:UIButton!)
{
print("Button \(sender.tag) tapped")
var tag = sender.tag
print(sender.currentTitle!)
if sender.currentTitle! == "" {
sender.titleLabel!.font = UIFont(name: "chalkduster", size: fontSizeTag)
sender.setTitleColor(UIColor.redColor(), forState: .Normal)
sender.setTitle("X", forState: UIControlState.Normal)
} else if sender.currentTitle! == "X" {
sender.titleLabel!.font = UIFont(name: "chalkduster", size: fontSizeTag)
sender.setTitleColor(UIColor.greenColor(), forState: .Normal)
sender.setTitle("O", forState: UIControlState.Normal)
}else if sender.currentTitle! == "O" {
sender.titleLabel!.font = UIFont(name: "chalkduster", size: fontSizeTag)
//sender.setTitleColor(UIColor.greenColor(), forState: .Normal)
sender.setTitle("", forState: UIControlState.Normal)
}
}
这为我提供了右键,但无法访问其中的标题。
@IBAction func deleteAnswers(sender: UIBarButtonItem) {
var totalBoxes = getTotalNumberOfBoxesInGrid()
var tag = Int()
for tag = 1; tag <= totalBoxes; tag++ {
let button = self.view.viewWithTag(tag) as? UIButton
button!.setTitle("", forState: UIControlState.Normal)
}
}
实际上在第二部分更改空字符串&#34;&#34; (无标题)写信,说&#34; P&#34;只需打印一个&#34; P&#34;超过现有的头衔。如何访问原始标题?
答案 0 :(得分:0)
我用这个解决方案在我的头脑中醒来,它有效。然而,它是一个解决方案而不是严格的问题答案:即如何访问使用send.setTitle设置的按钮标题。当&#34;发件人&#34;仅用于获取标记#并设置按钮标题,因为我在下面设置它们,删除以及访问信息工作所需的其他功能。
func buttonAction(sender:UIButton!)
{
print("Button \(sender.tag) tapped")
var tag = sender.tag
print(sender.currentTitle!)
if var button = self.view.viewWithTag(tag) as? UIButton {
if button.currentTitle! == "" {
button.titleLabel!.font = UIFont(name: "chalkduster", size: fontSizeTag)
button.setTitleColor(UIColor.redColor(), forState: .Normal)
button.setTitle("X", forState: UIControlState.Normal)
myUserValuesDictionary[globalAppD.newPuzzle.name]![tag] = 1
} else if button.currentTitle! == "X" {
button.titleLabel!.font = UIFont(name: "chalkduster", size: fontSizeTag)
button.setTitleColor(UIColor.greenColor(), forState: .Normal)
button.setTitle("O", forState: UIControlState.Normal)
myUserValuesDictionary[globalAppD.newPuzzle.name]![tag] = 2
}else if button.currentTitle! == "O" {
button.titleLabel!.font = UIFont(name: "chalkduster", size: fontSizeTag)
//button.setTitleColor(UIColor.greenColor(), forState: .Normal)
button.setTitle("", forState: UIControlState.Normal)
myUserValuesDictionary[globalAppD.newPuzzle.name]![tag] = 0
}
}
}