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?
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.