Ios 播放完成后更改按钮图像

Ios 播放完成后更改按钮图像,ios,objective-c,swift,Ios,Objective C,Swift,当我单击“播放”按钮时,“发件人”按钮会更改,但当我单击“表格视图”中的另一个按钮时,按钮的第一个按钮图像不会更改为“播放” @IBAction func playSound(sender: UIButton) { if self.player != nil && self.player.playing { player.stop() sender.setImage(UIImage(named: "play.png"), forS

当我单击“播放”按钮时,“发件人”按钮会更改,但当我单击“表格视图”中的另一个按钮时,按钮的第一个按钮图像不会更改为“播放”

 @IBAction func playSound(sender: UIButton) {
if self.player != nil && self.player.playing {
            player.stop()
            sender.setImage(UIImage(named: "play.png"), forState: UIControlState.Normal)            
        }
else {
sender.setImage(UIImage(named: "pause.png"), forState: UIControlState.Normal) 
}
}


尝试为按钮设置背景图像

let image = UIImage(named: "play.png") as UIImage
sender.setBackgroundImage(image, forState: UIControlState.Normal)

希望这有帮助。

尝试为按钮设置背景图像

let image = UIImage(named: "play.png") as UIImage
sender.setBackgroundImage(image, forState: UIControlState.Normal)

希望这有帮助。

是呼叫单选按钮。我从不在手机里使用单选按钮。这对我来说很难。我是新手。如果你需要它,它就是:。 但我用另一种方式:didSelectRowAtIndexPath。在单元格中单击时,当前按钮为“显示暂停图像”,其他按钮为“显示播放图像”。你可以参考它

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    currentIndexPath = indexPath;
    YourTableViewCell *cell = nil;

    if (!previousIndexPath) {
        previousIndexPath = currentIndexPath;
    } 
    if (previousIndexPath != currentIndexPath) {
        cell = (YourTableViewCell *) [_yourTableView cellForRowAtIndexPath:previousIndexPath];
        [cell.radioBtn setBackgroundImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];
        cell = (YourTableViewCell *) [_yourTableView  cellForRowAtIndexPath:currentIndexPath];
        [cell.radioBtn setBackgroundImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
        previousIndexPath = currentIndexPath;
    }


    if (previousIndexPath == currentIndexPath) {
        cell = (YourTableViewCell *) [_yourTableView  cellForRowAtIndexPath:previousIndexPath];
        [cell.radioBtn setBackgroundImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
    }
}

是那个呼叫单选按钮。我从不在手机里使用单选按钮。这对我来说很难。我是新手。如果你需要它,它就是:。 但我用另一种方式:didSelectRowAtIndexPath。在单元格中单击时,当前按钮为“显示暂停图像”,其他按钮为“显示播放图像”。你可以参考它

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    currentIndexPath = indexPath;
    YourTableViewCell *cell = nil;

    if (!previousIndexPath) {
        previousIndexPath = currentIndexPath;
    } 
    if (previousIndexPath != currentIndexPath) {
        cell = (YourTableViewCell *) [_yourTableView cellForRowAtIndexPath:previousIndexPath];
        [cell.radioBtn setBackgroundImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];
        cell = (YourTableViewCell *) [_yourTableView  cellForRowAtIndexPath:currentIndexPath];
        [cell.radioBtn setBackgroundImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
        previousIndexPath = currentIndexPath;
    }


    if (previousIndexPath == currentIndexPath) {
        cell = (YourTableViewCell *) [_yourTableView  cellForRowAtIndexPath:previousIndexPath];
        [cell.radioBtn setBackgroundImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
    }
}


如果条件{self.btnmale.setBackgroundImage(UIImage(名为:“imagename”)!,forState:.Normal)}其他条件{self.btnmale.setBackgroundImage(UIImage(名为:“imagename1”)!,forState:.Normal)}我已经这样做了,看到上面的代码了吗?你使用Tableview创建播放音频文件了吗?是的,我有一个table view,然后在table view单元格中我有声音按钮,你能给我显示你的屏幕UI吗?如果条件是{self.btnmale.setBackgroundImage(UIImage(名为:“imagename”)!,for state:.Normal)}其他{self.btnmale.setBackgroundImage(UIImage(名为:“imagename1”)!,forState:.Normal)}我已经这样做了,看到上面的代码了吗?你使用Tableview创建播放音频文件了吗?是的,我有一个table view,然后在table view单元格中我有声音按钮,你能给我显示你的屏幕界面吗?当你点击单元格,但我没有点击单元格,我点击单元格中的按钮,我知道,你需要阅读:链接收音机,但我的ans中UItableViewCells中的ton逻辑。这是U的解决方案。使用委派我实现了你的答案,但不起作用,DidSelectedRow..与单击单元格而不是按钮有关,我只想单击按钮,哦,不。UItableViewCells中的单选按钮逻辑是单击单元格中的按钮。这不是我的方式。当你单击单元格但我没有点击单元格我点击单元格中的按钮我知道,你需要阅读:UItableViewCells中的链接单选按钮逻辑我的ans中的单元格。这是针对你的解决方案。使用委派我实现了你的答案,但不起作用,DidSelectedRow..与点击单元格而不是按钮有关,我只想点击按钮,哦,不。单选按钮逻辑在U中ItableViewCells是单元格中的单击按钮。这不是我的方式。让播放:UIButton=(cell.viewWithTag(11)as!UIButton)这一行显示故事板表格中的编译错误ViewCellPlay按钮给一个标记11,这样你的错误就消失了。不,卡在IF条件下当应用程序运行时,你会遇到什么样的错误。让我们一起播放:UIButton=(cell.viewWithTag(11)as!UIButton)这一行显示了故事板表格中的编译错误ViewCell play按钮给出一个标记11,这样你的错误就消失了。不,卡在IF条件中。当应用程序运行时,你会遇到什么样的错误?让我们来看看。