我在InterfaceBuilder中创建了一个UISwitch来打开和关闭音频。该开关工作正常,但我想将画外音从当前的'0'和'1'读出的值更改为'Off'和'On'。我的代码如下:
import UIKit
class AudioStreamTableViewCell: UITableViewCell {
weak var controller: EventDetailsViewController!
weak var audioInterface: EventAudioInterface? { didSet { if self.audioInterface !== oldValue { self.updateUI() }}}
func updateUI() {}
override func awakeFromNib() {
super.awakeFromNib()
self.updateUI()
}
}
class MuteStreamTableViewCell: AudioStreamTableViewCell {
static let identifier = "MuteStreamTableViewCell"
@IBOutlet var muteSwitch: UISwitch!
override func updateUI() {
self.muteSwitch.isOn = self.audioInterface?.muted ?? false
}
@IBAction func switchChanged(_ muteSwitch: UISwitch) {
self.controller.setMuted(muteSwitch.isOn, on: self.audioInterface)
if muteSwitch.isOn {
self.muteSwitch.accessibilityValue = "on"
} else {
self.muteSwitch.accessibilityValue = "off"
}
}
}
画外音仍然会说“0”和“1”。我做错了什么?
谢谢!
答案 0 :(得分:2)
我不得不继承UISwitch
并重写accessibilityValue
。
class AccessibilityUiSwitch: UISwitch {
override var accessibilityValue: String? {
get {
return isOn ? "on" : "off"
}
set {
self.accessibilityValue = newValue
}
}
}