Skip to content

[Fix] Accessibility element's bounding rect will get wrong if the con…#803

Open
Mishidexfc wants to merge 1 commit into
TTTAttributedLabel:masterfrom
Mishidexfc:mishidexfc/FixAccessibilityElement
Open

[Fix] Accessibility element's bounding rect will get wrong if the con…#803
Mishidexfc wants to merge 1 commit into
TTTAttributedLabel:masterfrom
Mishidexfc:mishidexfc/FixAccessibilityElement

Conversation

@Mishidexfc
Copy link
Copy Markdown

@Mishidexfc Mishidexfc commented Oct 28, 2019

Repro steps:

  1. Using AddLinkToURL: to add two urls inside the text, such as ‘Affogato’ and ‘mylink’.Note that the text must contain ‘\n’ character to repro this bug.
    label.text = @"Affogato: Espresso served over gelato. Traditionally vanilla is used, but some coffeehouses or customers use any flavor \n \n 123 mylink.";

  2. If the label’s layout was not set correctly before adding the link, the last accessibility element will get the wrong boundingRect (all zero) from the return value of boundingREctForCharacterRange:

  3. boundingREctForCharacterRange: using label’s bounding size to measure the position of the highlighted element but the textContainer seems to ignore the ‘\n’ character will have additional line.

  4. Thus, if user setting the correct frame such as using sizeToFit, it works fine. But if the user calls it later after adding the link, the position of accessibilityElement will get wrong.

Solution:
NSTextContainer’s size does not need to be the same as the label’s bounding size.
Instead, we can use
CGSizeMake(self.bounds.size.width, CGFLOAT_MAX)

ericbomgardner pushed a commit to quizlet/TTTAttributedLabel that referenced this pull request Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant