4
votes

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 (i.e 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?

1
If you have a proper label, it is not clear to me why you would also want to display the same text as a placeholder. That is like a belt-and-braces approach, unless the label is not visible.Tsundoku
Hi Christopher, thanks for going through my question. If some user are blind then they should get voice over feedback with help of UITextField.accessibilityLabel (i.e Placeholder is not visible to him).DevesH

1 Answers

5
votes

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.