0

我正在为益智匹配游戏编写代码。我用 a 定义了 a UIButtonUIImage我添加了一个目标来改变UIImagea 的 a UIButton。我希望这张照片出现,直到我点击另一个UIButton或相同的UIButton,我该怎么做?!

UIButton

mybutton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[mybutton1 addTarget:self 
              action:@selector(method:) 
    forControlEvents:UIControlEventTouchDown];
question = [UIImage imageNamed:@"puzzle.jpg"];
[mybutton1 setBackgroundImage:question 
                     forState:UIControlStateNormal];

然后方法:

-(void) method: (UIButton*) sender{
    [sender setBackgroundImage:[UIImage imageNamed: @"cheerful-cat.jpg"] 
                      forState:UIControlStateNormal];
}
4

1 回答 1

0

试试这个方法。。

Button*  mybutton1= [UIButton buttonWithType:UIButtonTypeCustom];
[mybutton1 addTarget:self 
              action:@selector(method:) 
    forControlEvents:UIControlEventTouchDown];
question = [UIImage imageNamed:@"puzzle.jpg"];
[mybutton1 setBackgroundImage:question 
                     forState:UIControlStateNormal];

-(void) method: (UIButton*) sender{
    [sender setBackgroundImage:[UIImage imageNamed: @"cheerful-cat.jpg"] 
                      forState:UIControlStateNormal];
}
于 2013-10-08T13:18:58.020 回答