ios - UIButtonBarItem 没有改变

标签 ios swift uibarbuttonitem

我在 iOS 应用程序中有一个底部工具栏,它只包含一个用于播放/暂停直播 Icecast 广播流的按钮。一切正常,除了按钮从播放图标变为暂停图标,反之亦然。这是我的代码。

@IBAction func PlayStop(_ sender: Any) {
        if player.timeControlStatus == .playing {
            // Stop the live radio stream
            player.pause()
            // Set the radio tower image to off with Alpha 0.3
            TowerImage.image = UIImage(named: "TowerOff")
            TowerImage.alpha = 0.3
            // Set the Toolbar icon to the Play Icon
            PlayStopButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.play, target: self, action: #selector(ViewController.PlayStop(_:)))
        } else if player.timeControlStatus != .playing {
            // Play the live radio stream
            player.play()
            // Set the radio tower image to on with Alpha 1
            TowerImage.image = UIImage(named: "TowerOn")
            TowerImage.alpha = 1
            // Set the Toolbar icon to the Pause Icon
            PlayStopButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.pause, target: self, action: #selector(ViewController.PlayStop(_:)))
        }
    }
    @IBOutlet var TowerImage: UIImageView!
    @IBOutlet var PlayStopButton: UIBarButtonItem!

最佳答案

然后你想把工具栏卡在 socket 上

let playStopButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.pause, target: self, action: #selector(ViewController.PlayStop(_:)))  
self.toolBar.items = [playStopButton]

关于ios - UIButtonBarItem 没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53974290/

相关文章:

swift - 单击按钮将移动到下一个 Controller ?

ios - 如何在iOS 11中正确添加状态栏模糊效果而不发出警告?

ios - 随时间改变 iPhone 手电筒强度 (Swift)

swift - 快速添加 UIBarButton 项目

iphone - 奇怪的 UIBarButtonItem 行为

iOS:如何旋转 CGImage 并将其绘制到 UIImage 上?

ios - iOS 中的 SOAP 请求

iphone - iOS 如何加密和解密二进制文件?

ios - 无法从 UISegmentedControl 重新加载表数据

ios - 重新实例化 Storyboard导航栏按钮