【问题标题】:Changing images on buttons via other buttons通过其他按钮更改按钮上的图像
【发布时间】:2012-03-15 15:02:32
【问题描述】:

有没有办法通过按下另一个按钮来更改按钮的图像?

我有一个播放按钮,按下该按钮后,图像变为暂停,反之亦然。

现在,我有一个停止按钮,我需要再次将播放按钮图像设置为播放(因为它与暂停按钮保持一致)。

对此有何建议?

- (IBAction)play:(id)sender 
{
    UIImage *playImage = [[UIImage alloc] initWithContentsOfFile:
    [[NSBundle mainBundle] pathForResource:@"playFinal" ofType:@"png"]];
    UIImage *pauseImage = [[UIImage alloc] initWithContentsOfFile:
    [[NSBundle mainBundle] pathForResource:@"pauseFinal" ofType:@"png"]];

    if ([self.background isPlaying]) 
    {
        [sender setImage:playImage forState:UIControlStateNormal];
        [self.background pause];
    }
    else 
    {
        [sender setImage:pauseImage forState:UIControlStateNormal];
        [self.background play]; 
    }
}

- (IBAction)stop 
{
    UIImage *playImage = [[UIImage alloc] initWithContentsOfFile:
    [[NSBundle mainBundle] pathForResource:@"playFinal" ofType:@"png"]];

    // What has to be done here?

    [self.background stop];
    [self.background setCurrentTime:0];
}

【问题讨论】:

  • 应该可以通过修改内部HTML来实现。你能发布你到目前为止的代码吗?
  • 我认为在这种情况下代码是没用的。我在主帖中更清楚地描述了我的情况。
  • 我问的原因是为了修改内部 HTML,我们需要知道已经存在的内容。你能发一个小提琴吗?
  • 代码现在在主帖中。
  • 对不起,伙计。不知道这个

标签: ios uibutton uiimage


【解决方案1】:

为您的按钮定义一个出口,例如:

@property (nonatomic, strong)  IBOutlet UIButton *playButton;

将它连接到界面生成器中的按钮,然后:

[playButton setImage:playImage forState:UIControlStateNormal];
[self.background stop];
...

【讨论】:

  • 嗯,这确实有效!给你大忙,先生!从来没有想过这样的方式:)
猜你喜欢
  • 1970-01-01
  • 2014-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多