I've created a UISwitch in InterfaceBuilder to toggle audio on and off. The switch works fine, but I want to change the value that Voiceover reads out from the current '0' and '1' to 'Off' and 'On'. My code is as follows:
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 still speaks '0' and '1'. What am I doing wrong?
Thanks!!
I had to subclass UISwitch
and override accessibilityValue
.
class AccessibilityUiSwitch: UISwitch {
override var accessibilityValue: String? {
get {
return isOn ? "on" : "off"
}
set {
self.accessibilityValue = newValue
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.