ios - Limiting text read by VoiceOver from a UILabel -
i'm creating app similar mail (or messages or notes) displays uitableviewcell
s contain message preview. text doesn't fit in uilabel
, text truncated , ellipsis displayed automatically. works in app sighted users, when using voiceover entire text
content of uilabel
read aloud. not occur in mail - voiceover stops announcing text upon reaching ellipsis.
how can obtain same behavior in app mail - enforce voiceover stop announcing text when reaches ellipsis?
cell.messagepreviewlabel.text = a_potentially_really_long_string_here
here subclass of uilabel want. note, have gone 0 effort optimize this. part you. overall recommendation, accessibility point of view, still leave it. overriding accessibility label portray portion of text in actual label questionable thing a11y perspective. use tool carefully!
@interface cmpreivewlabel : uilabel @end @implementation cmpreviewlabel - (nsstring*)accessibilitylabel { return [self stringthatfits]; } - (nsstring*)stringthatfits { if (self.numberoflines != 1) return @"this class need modifications support more 1 line previews"; const int width = self.bounds.size.width; nsmutableattributedstring* resultstring = [[nsmutableattributedstring alloc] initwithattributedstring:self.attributedtext]; while (width < resultstring.size.width) { nsrange range = [resultstring.string rangeofstring:@" " options:nsbackwardssearch]; range.length = resultstring.length - range.location; [resultstring.mutablestring replacecharactersinrange:range withstring:@""]; } return resultstring.string; } @end
Comments
Post a Comment