2014-09-11 67 views
0

这个问题对iPhone应用程序 您好,我试图让一个小任务:通过单击和取消单击按钮更改图像为iphone?

  1. 默认的界面具有图像和2个按钮,

  2. ,当你点击了按钮,它改变图像和按钮保持点击(我认为选择)

  3. 当我再次按下按钮时,图像将返回到原始图像。

  4. 如果我按了2个按钮,它会更改为另一个新图像,表示两个按钮都被按下了。

我能够达到第2步,但我不知道如何做第3步和第4步。有人可以帮我吗?这是我走到这一步,代码:上viewcontroller.h

@interface ViewController : UIViewController - (IBAction)buttonPressedRight:(UIButton *)sender; 

    @property (weak, nonatomic) IBOutlet UIImageView *imageView; 

    - (IBAction)buttonPressed:(UIButton *)sender;@property (weak, nonatomic) IBOutlet UILabel *label 

和viewcontroller.m,代码为两个按钮相同

- (IBAction)buttonPressed:(UIButton *)sender { 
    NSString *title = [sender titleForState:(UIControlState)UIControlStateNormal]; 
    NSString *newText = [NSString stringWithFormat:@"%@ button pressed.",title]; 

    _label.text = newText; 
    UIImage *image1 = [UIImage imageNamed:@"num1.png"] ; 
    _imageView.image = image1; 

    sender.selected = !sender.selected; 
} 
+0

您是否对两个按钮使用相同的操作事件? – Rashad 2014-09-11 04:05:33

+0

是的,我为两个按钮使用相同的事件 – RLe 2014-09-12 04:15:37

回答

0

就像按下物理按钮时(选定)它返回之前,您不能再按一次。

所以要达到3.when i press on the button again, the image go back to the original image.你不应该按下时选择你的按钮。相反,您可以更改按钮的外观和标题,以指示现在选择按钮。

我认为这也适用于4.xxxx