简体   繁体   中英

Is there any way to disable accessibility voice-over of placeholder text in UITextField?

I am using UITextField for search text bar in my app. I always want to set accessibiliyLabel to text field as "Search for file". I also want to set placeholder to "Search for file".

But when i start iOS voice-over and if input text in " "(empty) then Search for file is spoken twice (ie one form accessibilityLabel and another form placeholder). If some input text in present in text field that only accessibilityLabel is spoken along with input text.

Is there any way to disable placeholder text accessibility?

Found this answer here :

class MyTextField: UITextField {
    override public var accessibilityValue: String? {
        get { return self.text }
        set { super.accessibilityValue = newValue }
    }
}

You're going to prevent your UITextField from using your placeholder as the accessibilityValue by always returning the text attribute instead. Have in mind that using something like textField.accessibilityValue = text won't work.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM