【问题标题】:How change the current image's button on Click?如何更改单击时当前图像的按钮?
【发布时间】:2011-12-07 15:11:37
【问题描述】:

在我的文件 .h 中:

-(IBAction)Boutton:(id)sender;

在我的文件 .m 中:

-(IBAction)Boutton:(id)sender
{ 

    UIImage *btnImage1 = [UIImage imageNamed:@"x.png"];
    [sender setImage:btnImage1 forState:UIControlStateNormal];

}

使用此代码,我可以更改单击按钮(发件人)的图像。

问题是,如何更改其他按钮(不是发件人按钮)的图像

例如,如果(sender.tag == 4) 我想拥有类似的东西:

-(IBAction)Boutton:(id)sender
{ 

    UIImage *btnImage1 = [UIImage imageNamed:@"x.png"];
    [sender setImage:btnImage1 forState:UIControlStateNormal];

    UIImage *btnImage2 = [UIImage imageNamed:@"Y.png"];

    [Boutton:(1) setImage:btnImage2 forState:UIControlStateNormal];
    [Boutton:(2) setImage:btnImage2 forState:UIControlStateNormal];
    [Boutton:(3) setImage:btnImage2 forState:UIControlStateNormal];

}

【问题讨论】:

    标签: objective-c xcode image button


    【解决方案1】:

    只需将其他按钮链接到 UIViewController 子类的插座。这样您就可以从-(IBAction)Boutton:(id)sender 中通过它们的属性访问它们来更改它们的图像。

    【讨论】:

      【解决方案2】:

      问题是,我怎样才能改变其他按钮(不是发件人)的图像?

      使用 UIButton 的标签参数。

      UIButton *btn = (UIButton *)sender;
      
      if(btn.tag == 1)
      {
      ...
      }
      

      【讨论】:

        【解决方案3】:

        选择按钮并分配您想要的图像,然后从实用工具栏中将状态配置更改为突出显示,然后分配点击图像

        请看下面的屏幕截图

        screen shot

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-07-24
          • 1970-01-01
          • 1970-01-01
          • 2013-11-05
          • 2011-07-02
          • 1970-01-01
          • 2018-04-14
          相关资源
          最近更新 更多