我在InterfaceBuilder中创建了一个UISwitch来切换音频的开关。这个开关工作得很好,但我想把Voiceover读出的当前值'0'和'1'改为'关闭'和'打开'。我的代码如下:
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"
}
}
}
语音指南 (Voiceover) 仍在说 '0' 和 '1',我做错了什么吗?
谢谢!!
accessibilityLabel
而不是:https://developer.apple.com/documentation/objectivec/nsobject/1615181-accessibilitylabel - Mike Taverne